mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
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;
23 lines
643 B
TypeScript
23 lines
643 B
TypeScript
import { renderHook } from '@testing-library/react-hooks';
|
|
import { useRendersCount } from '../src';
|
|
|
|
describe('useRendersCount', () => {
|
|
it('should be defined', () => {
|
|
expect(useRendersCount).toBeDefined();
|
|
});
|
|
|
|
it('should return number', () => {
|
|
expect(renderHook(() => useRendersCount()).result.current).toEqual(expect.any(Number));
|
|
});
|
|
|
|
it('should return actual number of renders', () => {
|
|
const hook = renderHook(() => useRendersCount());
|
|
|
|
expect(hook.result.current).toBe(1);
|
|
hook.rerender();
|
|
expect(hook.result.current).toBe(2);
|
|
hook.rerender();
|
|
expect(hook.result.current).toBe(3);
|
|
});
|
|
});
|