@@ -30,10 +30,7 @@ describe('useIsFetching', () => {
30
30
31
31
useQuery ( {
32
32
queryKey : key ,
33
- queryFn : async ( ) => {
34
- await sleep ( 50 )
35
- return 'test'
36
- } ,
33
+ queryFn : ( ) => sleep ( 50 ) . then ( ( ) => 'test' ) ,
37
34
enabled : ready ,
38
35
} )
39
36
@@ -54,10 +51,8 @@ describe('useIsFetching', () => {
54
51
expect ( getByText ( 'isFetching: 0' ) ) . toBeInTheDocument ( )
55
52
56
53
fireEvent . click ( getByRole ( 'button' , { name : / s e t R e a d y / i } ) )
57
-
58
54
await vi . advanceTimersByTimeAsync ( 0 )
59
55
expect ( getByText ( 'isFetching: 1' ) ) . toBeInTheDocument ( )
60
-
61
56
await vi . advanceTimersByTimeAsync ( 51 )
62
57
expect ( getByText ( 'isFetching: 0' ) ) . toBeInTheDocument ( )
63
58
} )
@@ -80,21 +75,15 @@ describe('useIsFetching', () => {
80
75
function FirstQuery ( ) {
81
76
useQuery ( {
82
77
queryKey : key1 ,
83
- queryFn : async ( ) => {
84
- await sleep ( 100 )
85
- return 'data'
86
- } ,
78
+ queryFn : ( ) => sleep ( 100 ) . then ( ( ) => 'data' ) ,
87
79
} )
88
80
return null
89
81
}
90
82
91
83
function SecondQuery ( ) {
92
84
useQuery ( {
93
85
queryKey : key2 ,
94
- queryFn : async ( ) => {
95
- await sleep ( 100 )
96
- return 'data'
97
- } ,
86
+ queryFn : ( ) => sleep ( 100 ) . then ( ( ) => 'data' ) ,
98
87
} )
99
88
return null
100
89
}
@@ -133,21 +122,15 @@ describe('useIsFetching', () => {
133
122
function One ( ) {
134
123
useQuery ( {
135
124
queryKey : key1 ,
136
- queryFn : async ( ) => {
137
- await sleep ( 10 )
138
- return 'test'
139
- } ,
125
+ queryFn : ( ) => sleep ( 10 ) . then ( ( ) => 'test' ) ,
140
126
} )
141
127
return null
142
128
}
143
129
144
130
function Two ( ) {
145
131
useQuery ( {
146
132
queryKey : key2 ,
147
- queryFn : async ( ) => {
148
- await sleep ( 20 )
149
- return 'test'
150
- } ,
133
+ queryFn : ( ) => sleep ( 20 ) . then ( ( ) => 'test' ) ,
151
134
} )
152
135
return null
153
136
}
@@ -174,15 +157,13 @@ describe('useIsFetching', () => {
174
157
175
158
const { getByText, getByRole } = renderWithClient ( queryClient , < Page /> )
176
159
177
- getByText ( 'isFetching: 0' )
160
+ expect ( getByText ( 'isFetching: 0' ) ) . toBeInTheDocument ( )
178
161
179
162
fireEvent . click ( getByRole ( 'button' , { name : / s e t S t a r t e d / i } ) )
180
-
181
163
await vi . advanceTimersByTimeAsync ( 0 )
182
- getByText ( 'isFetching: 1' )
183
-
164
+ expect ( getByText ( 'isFetching: 1' ) ) . toBeInTheDocument ( )
184
165
await vi . advanceTimersByTimeAsync ( 11 )
185
- getByText ( 'isFetching: 0' )
166
+ expect ( getByText ( 'isFetching: 0' ) ) . toBeInTheDocument ( )
186
167
187
168
// at no point should we have isFetching: 2
188
169
expect ( isFetchingArray ) . toEqual ( expect . not . arrayContaining ( [ 2 ] ) )
@@ -195,10 +176,7 @@ describe('useIsFetching', () => {
195
176
function Page ( ) {
196
177
useQuery ( {
197
178
queryKey : key ,
198
- queryFn : async ( ) => {
199
- await sleep ( 10 )
200
- return 'test'
201
- } ,
179
+ queryFn : ( ) => sleep ( 10 ) . then ( ( ) => 'test' ) ,
202
180
} )
203
181
204
182
const isFetching = useIsFetching ( )
@@ -214,7 +192,6 @@ describe('useIsFetching', () => {
214
192
215
193
await vi . advanceTimersByTimeAsync ( 0 )
216
194
expect ( rendered . getByText ( 'isFetching: 1' ) ) . toBeInTheDocument ( )
217
-
218
195
await vi . advanceTimersByTimeAsync ( 11 )
219
196
expect ( rendered . getByText ( 'isFetching: 0' ) ) . toBeInTheDocument ( )
220
197
} )
@@ -227,10 +204,7 @@ describe('useIsFetching', () => {
227
204
useQuery (
228
205
{
229
206
queryKey : key ,
230
- queryFn : async ( ) => {
231
- await sleep ( 10 )
232
- return 'test'
233
- } ,
207
+ queryFn : ( ) => sleep ( 10 ) . then ( ( ) => 'test' ) ,
234
208
} ,
235
209
queryClient ,
236
210
)
0 commit comments