diff --git a/src/__tests__/usePrevious.test.tsx b/src/__tests__/usePrevious.test.tsx new file mode 100644 index 00000000..70713653 --- /dev/null +++ b/src/__tests__/usePrevious.test.tsx @@ -0,0 +1,22 @@ +import { cleanup, renderHook } from 'react-hooks-testing-library'; +import usePrevious from '../usePrevious'; + +afterEach(cleanup); + +describe('usePrevious', () => { + it('should be defined', () => { + expect(usePrevious).toBeDefined(); + }); + + const hook = renderHook(props => usePrevious(props), { initialProps: 0 }); + + it('should return undefined on initial render', () => { + expect(hook.result.current).toBe(undefined); + }); + + it('should return previous state after update', () => { + hook.rerender(1); + hook.rerender(2); + expect(hook.result.current).toBe(1); + }); +});