react-use/tests/useFirstMountState.test.ts
Anton Zinovyev 30abe2b22e
feat: add useFirstMountState & useRendersCount hooks (#769)
feat(useFirstMountState): hook to track if render is first;
feat(useRendersCount): hook to track renders count;
refactor(useUpdateEffect): now uses useFirstMountState hook;
refactor(usePreviousDistinct): now uses with useFirstMountState hook;
docs: update readme;
2019-11-23 15:14:35 +03:00

23 lines
691 B
TypeScript

import { renderHook } from '@testing-library/react-hooks';
import { useFirstMountState } from '../src';
describe('useFirstMountState', () => {
it('should be defined', () => {
expect(useFirstMountState).toBeDefined();
});
it('should return boolean', () => {
expect(renderHook(() => useFirstMountState()).result.current).toEqual(expect.any(Boolean));
});
it('should return true on first render and false on all others', () => {
const hook = renderHook(() => useFirstMountState());
expect(hook.result.current).toBe(true);
hook.rerender();
expect(hook.result.current).toBe(false);
hook.rerender();
expect(hook.result.current).toBe(false);
});
});