useUniqueId.test.ts 790 B

123456789101112131415161718192021222324
  1. import { renderHook } from '@testing-library/react-hooks';
  2. import { useUniqueId } from './useUniqueId';
  3. describe('useUniqueId', () => {
  4. it('should work correctly', () => {
  5. const { result: resultA, rerender: rerenderA } = renderHook(() => useUniqueId());
  6. const { result: resultB, rerender: rerenderB } = renderHook(() => useUniqueId());
  7. // the values of the separate hooks should be different
  8. expect(resultA.current).not.toBe(resultB.current);
  9. // we copy the current values after the first render
  10. const firstValueA = resultA.current;
  11. const firstValueB = resultB.current;
  12. rerenderA();
  13. rerenderB();
  14. // we check that the value did not change
  15. expect(resultA.current).toBe(firstValueA);
  16. expect(resultB.current).toBe(firstValueB);
  17. });
  18. });