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
22 lines
721 B
TypeScript
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);
|
|
});
|