mirror of
https://github.com/streamich/react-use.git
synced 2025-12-08 18:02:14 +00:00
24 lines
614 B
TypeScript
24 lines
614 B
TypeScript
import { renderHook } from '@testing-library/react-hooks';
|
|
import { useUpdateEffect } from '../src';
|
|
|
|
it('should run effect on update', () => {
|
|
const effect = jest.fn();
|
|
|
|
const { rerender } = renderHook(() => useUpdateEffect(effect));
|
|
expect(effect).not.toHaveBeenCalled();
|
|
|
|
rerender();
|
|
expect(effect).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('should run cleanup on unmount', () => {
|
|
const cleanup = jest.fn();
|
|
const effect = jest.fn().mockReturnValue(cleanup);
|
|
const hook = renderHook(() => useUpdateEffect(effect));
|
|
|
|
hook.rerender();
|
|
hook.unmount();
|
|
|
|
expect(cleanup).toHaveBeenCalledTimes(1);
|
|
});
|