File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 1
1
import { act , renderHook } from '@testing-library/react-hooks' ;
2
2
import { useInfinitePagination } from '..' ;
3
+ import { cache } from 'swr' ;
3
4
4
5
const timeout = ( ms : number ) => {
5
6
return new Promise < void > ( ( resolve ) => {
@@ -81,10 +82,16 @@ describe('useInfinitePagination', () => {
81
82
await act ( async ( ) => {
82
83
await timeout ( 150 ) ;
83
84
result . current [ 1 ] . loadMore ( ) ;
85
+ result . current [ 1 ] . loadMore ( ) ;
84
86
await timeout ( 150 ) ;
85
87
expect ( result . current [ 0 ] . length ) . toStrictEqual ( 15 ) ;
86
88
expect ( result . current [ 1 ] . isLoading ) . toEqual ( false ) ;
87
89
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 ) ;
88
95
} ) ;
89
96
} ) ;
90
97
@@ -99,4 +106,11 @@ describe('useInfinitePagination', () => {
99
106
expect ( result . current [ 1 ] . isReachingEnd ) . toEqual ( false ) ;
100
107
} ) ;
101
108
} ) ;
109
+
110
+ afterEach ( async ( ) => {
111
+ await new Promise < void > ( ( resolve ) => {
112
+ resolve ( ) ;
113
+ } ) ;
114
+ cache . clear ( ) ;
115
+ } ) ;
102
116
} ) ;
You can’t perform that action at this time.
0 commit comments