Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
heyjul3s committed Feb 28, 2021
1 parent 180bbff commit 777d0a3
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/usepreviousvalue/__tests__/usepreviousvalue.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
import { renderHook } from '@testing-library/react-hooks';
import { usePreviousValue } from '../src';

const usePreviousValueHook = () =>
renderHook(({ state }) => usePreviousValue(state), {
initialProps: { state: 0 }
});

describe('@artifak/usepreviousvalue', () => {
it('needs tests', () => {
//
it('should be undefined initially', () => {
const { result } = usePreviousValueHook();
expect(result.current).toBeUndefined();
});

it('should return previous state value on rerender', async () => {
const { result, rerender } = usePreviousValueHook();
rerender({ state: 1 });
expect(result.current).toBe(0);

rerender({ state: 2 });
expect(result.current).toBe(1);
});
});

0 comments on commit 777d0a3

Please sign in to comment.