mirror of
https://github.com/streamich/react-use.git
synced 2025-12-08 18:02:14 +00:00
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
36 lines
905 B
TypeScript
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);
|
|
});
|