react-use/tests/usePrevious.test.ts
Anton Zinovyev 8de2a3ee13 chore: move tests to top level /tests folder
chore: move all the tests to the separate directory outside of sources;

chore: remove jest.config.js (config moved to the package.json);

test: unused import in test;

test: 💍 fix tests add back x and y to useMeasure

chore: 🤖 add linter to /tests folder

ci: 🎡 limit Jest worker count for CircleCI
2019-11-08 16:55:34 -05:00

24 lines
635 B
TypeScript

import { renderHook } from '@testing-library/react-hooks';
import usePrevious from '../src/usePrevious';
const setUp = () => renderHook(({ state }) => usePrevious(state), { initialProps: { state: 0 } });
it('should return undefined on initial render', () => {
const { result } = setUp();
expect(result.current).toBeUndefined();
});
it('should always return previous state after each update', () => {
const { result, rerender } = setUp();
rerender({ state: 2 });
expect(result.current).toBe(0);
rerender({ state: 4 });
expect(result.current).toBe(2);
rerender({ state: 6 });
expect(result.current).toBe(4);
});