mirror of
https://github.com/streamich/react-use.git
synced 2026-01-25 14:17:16 +00:00
usePrevious tests
This commit is contained in:
parent
38687552a1
commit
dd5c1efd83
22
src/__tests__/usePrevious.test.tsx
Normal file
22
src/__tests__/usePrevious.test.tsx
Normal file
@ -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);
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user