Skip to content

Commit

Permalink
✅ update timer test
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnsonMao committed Dec 28, 2023
1 parent fa4bff7 commit 31bbd02
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/hooks/__tests__/useAutoReset.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { act, renderHook, waitFor } from '@testing-library/react';
import { act, renderHook } from '@testing-library/react';
import useAutoReset from '../useAutoReset';

describe('useAutoReset hook', () => {
Expand All @@ -7,15 +7,15 @@ describe('useAutoReset hook', () => {
const initialValue = false;
const newValue = true;
const { result } = renderHook(() => useAutoReset(initialValue));
jest.useFakeTimers();
// Assert
expect(result.current[0]).toBe(initialValue);
// Act
act(() => result.current[1](newValue));
// Assert
expect(result.current[0]).toBe(newValue);
await waitFor(
() => expect(result.current[0]).toBe(initialValue),
{ timeout: 2000 }
);
act(() => jest.runAllTimers());
expect(result.current[0]).toBe(initialValue);
jest.useRealTimers();
});
});

0 comments on commit 31bbd02

Please sign in to comment.