react-use/tests/useUpdate.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

36 lines
905 B
TypeScript

import { act, renderHook } from '@testing-library/react-hooks';
import useUpdate from '../src/useUpdate';
it('should init update function', () => {
const { result } = renderHook(() => useUpdate());
const update = result.current;
expect(update).toBeInstanceOf(Function);
});
it('should forces a re-render every time update function is called', () => {
let renderCount = 0;
const { result } = renderHook(() => {
renderCount++;
return useUpdate();
});
const update = result.current;
expect(renderCount).toBe(1);
act(() => update());
expect(renderCount).toBe(2);
act(() => update());
expect(renderCount).toBe(3);
});
it('should return same update function instance on each update', () => {
const { result, rerender } = renderHook(() => useUpdate());
const { current: updateCb } = result;
rerender();
expect(Object.is(result.current, updateCb)).toBe(true);
});