UNPKG

@vergiss/chooks

Version:
36 lines 961 B
import { renderHook } from '@testing-library/react-hooks'; import { useChangedProps } from '../index'; describe('useChangedProps', function () { it('should be defined', function () { expect(useChangedProps).toBeDefined(); }); it('should invoke callback', function () { var props = { name: 'coma' }; var callback = jest.fn().mockReturnValue(void 0); var hook = renderHook(function () { return useChangedProps(props, callback); }, { initialProps: props }); props = { name: 'cc' }; hook.rerender(); expect(callback).toBeCalledTimes(1); }); it('should not invoke callback', function () { var props = { name: 'coma' }; var callback = jest.fn().mockReturnValue(void 0); var hook = renderHook(function () { return useChangedProps(props, callback); }, { initialProps: props }); hook.rerender(); expect(callback).toBeCalledTimes(0); }); });