usePrevious tests

This commit is contained in:
Ward Oosterlijnck 2019-05-07 20:39:28 +10:00
parent 38687552a1
commit dd5c1efd83

View 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);
});
});