UNPKG

@vergiss/chooks

Version:
22 lines 633 B
import { act, renderHook } from '@testing-library/react-hooks'; import { useUnmount } from '../index'; describe('useUnmount', function () { it('should be defined', function () { expect(useUnmount).toBeDefined(); }); it('should invoke the callback only once', function () { var callback = jest.fn(); var hook = renderHook(function () { return useUnmount(callback); }); expect(callback).toBeCalledTimes(0); act(function () { hook.rerender(); }); expect(callback).toBeCalledTimes(0); act(function () { hook.unmount(); }); expect(callback).toBeCalledTimes(1); }); });