Skip to content

Commit c6eecef

Browse files
committed
test(daxus): cover more test for staleTime
1 parent 3a1d738 commit c6eecef

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

packages/daxus/src/__tests__/useAccessor-revalidateIfStale.test.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fireEvent, renderHook, waitFor } from '@testing-library/react';
1+
import { act, fireEvent, renderHook, waitFor } from '@testing-library/react';
22
import { useAccessor } from '../index.js';
33
import {
44
createControl,
@@ -53,6 +53,17 @@ describe('useAccessor-normal revalidateIfStale', () => {
5353
await waitFor(() => {
5454
expect(result.current.accessor.isStale()).toBe(true);
5555
});
56+
57+
await act(() => result.current.accessor.revalidate());
58+
expect(result.current.accessor.isStale()).toBe(false);
59+
await sleep(50);
60+
// refetch the data. This action should postpone the stale state being set to true.
61+
await act(() => result.current.accessor.revalidate());
62+
await sleep(60);
63+
expect(result.current.accessor.isStale()).toBe(false);
64+
await waitFor(() => {
65+
expect(result.current.accessor.isStale()).toBe(true);
66+
});
5667
});
5768

5869
test('should revalidate if the accessor is invalidated, and it is mounted', async () => {

0 commit comments

Comments
 (0)