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
33 lines
811 B
TypeScript
33 lines
811 B
TypeScript
import { renderHook } from '@testing-library/react-hooks';
|
|
import { useMount } from '../src';
|
|
|
|
const mockCallback = jest.fn();
|
|
|
|
afterEach(() => {
|
|
jest.resetAllMocks();
|
|
});
|
|
|
|
it('should call provided callback on mount', () => {
|
|
renderHook(() => useMount(mockCallback));
|
|
|
|
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('should not call provided callback on unmount', () => {
|
|
const { unmount } = renderHook(() => useMount(mockCallback));
|
|
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
|
|
unmount();
|
|
|
|
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('should not call provided callback on rerender', () => {
|
|
const { rerender } = renderHook(() => useMount(mockCallback));
|
|
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
|
|
rerender();
|
|
|
|
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
});
|