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

22 lines
721 B
TypeScript

import { renderHook } from '@testing-library/react-hooks';
import { useEffectOnce } from '../src';
const mockEffectCleanup = jest.fn();
const mockEffectCallback = jest.fn().mockReturnValue(mockEffectCleanup);
it('should run provided effect only once', () => {
const { rerender } = renderHook(() => useEffectOnce(mockEffectCallback));
expect(mockEffectCallback).toHaveBeenCalledTimes(1);
rerender();
expect(mockEffectCallback).toHaveBeenCalledTimes(1);
});
it('should run clean-up provided on unmount', () => {
const { unmount } = renderHook(() => useEffectOnce(mockEffectCallback));
expect(mockEffectCleanup).not.toHaveBeenCalled();
unmount();
expect(mockEffectCleanup).toHaveBeenCalledTimes(1);
});