Skip to content

Commit e02b7be

Browse files
author
qiaoyuwen
committed
fix: pagination test
1 parent e97ce44 commit e02b7be

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

packages/react-hooks/src/pagination/__tests__/index.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { act, renderHook } from '@testing-library/react-hooks';
22
import { useInfinitePagination } from '..';
3+
import { cache } from 'swr';
34

45
const timeout = (ms: number) => {
56
return new Promise<void>((resolve) => {
@@ -81,10 +82,16 @@ describe('useInfinitePagination', () => {
8182
await act(async () => {
8283
await timeout(150);
8384
result.current[1].loadMore();
85+
result.current[1].loadMore();
8486
await timeout(150);
8587
expect(result.current[0].length).toStrictEqual(15);
8688
expect(result.current[1].isLoading).toEqual(false);
8789
expect(result.current[1].isReachingEnd).toEqual(true);
90+
result.current[1].reset();
91+
await timeout(150);
92+
expect(result.current[0].length).toStrictEqual(10);
93+
expect(result.current[1].isLoading).toEqual(false);
94+
expect(result.current[1].isReachingEnd).toEqual(false);
8895
});
8996
});
9097

@@ -99,4 +106,11 @@ describe('useInfinitePagination', () => {
99106
expect(result.current[1].isReachingEnd).toEqual(false);
100107
});
101108
});
109+
110+
afterEach(async () => {
111+
await new Promise<void>((resolve) => {
112+
resolve();
113+
});
114+
cache.clear();
115+
});
102116
});

0 commit comments

Comments
 (0)