@@ -249,7 +249,10 @@ describe('queryObserver', () => {
249
249
test ( 'should always run the selector again if selector throws an error and selector is not referentially stable' , async ( ) => {
250
250
const key = queryKey ( )
251
251
const results : QueryObserverResult [ ] = [ ]
252
- const queryFn = ( ) => ( { count : 1 } )
252
+ const queryFn = async ( ) => {
253
+ await sleep ( 10 )
254
+ return { count : 1 }
255
+ }
253
256
const observer = new QueryObserver ( queryClient , {
254
257
queryKey : key ,
255
258
queryFn,
@@ -260,10 +263,10 @@ describe('queryObserver', () => {
260
263
const unsubscribe = observer . subscribe ( result => {
261
264
results . push ( result )
262
265
} )
263
- await sleep ( 1 )
266
+ await sleep ( 50 )
264
267
await observer . refetch ( )
265
268
unsubscribe ( )
266
- expect ( results . length ) . toBe ( 4 )
269
+ expect ( results . length ) . toBe ( 5 )
267
270
expect ( results [ 0 ] ) . toMatchObject ( {
268
271
status : 'loading' ,
269
272
isFetching : true ,
@@ -284,6 +287,11 @@ describe('queryObserver', () => {
284
287
isFetching : false ,
285
288
data : undefined ,
286
289
} )
290
+ expect ( results [ 4 ] ) . toMatchObject ( {
291
+ status : 'error' ,
292
+ isFetching : false ,
293
+ data : undefined ,
294
+ } )
287
295
} )
288
296
289
297
test ( 'should return stale data if selector throws an error' , async ( ) => {
@@ -293,7 +301,11 @@ describe('queryObserver', () => {
293
301
const error = new Error ( 'select error' )
294
302
const observer = new QueryObserver ( queryClient , {
295
303
queryKey : key ,
296
- queryFn : ( ) => ( shouldError ? 2 : 1 ) ,
304
+ retry : 0 ,
305
+ queryFn : async ( ) => {
306
+ await sleep ( 10 )
307
+ return shouldError ? 2 : 1
308
+ } ,
297
309
select : num => {
298
310
if ( shouldError ) {
299
311
throw error
@@ -306,11 +318,11 @@ describe('queryObserver', () => {
306
318
const unsubscribe = observer . subscribe ( result => {
307
319
results . push ( result )
308
320
} )
309
- await sleep ( 10 )
321
+ await sleep ( 50 )
310
322
await observer . refetch ( )
311
323
unsubscribe ( )
312
324
313
- expect ( results . length ) . toBe ( 4 )
325
+ expect ( results . length ) . toBe ( 5 )
314
326
expect ( results [ 0 ] ) . toMatchObject ( {
315
327
status : 'loading' ,
316
328
isFetching : true ,
@@ -335,6 +347,12 @@ describe('queryObserver', () => {
335
347
data : '1' ,
336
348
error,
337
349
} )
350
+ expect ( results [ 4 ] ) . toMatchObject ( {
351
+ status : 'error' ,
352
+ isFetching : false ,
353
+ data : '1' ,
354
+ error,
355
+ } )
338
356
} )
339
357
340
358
test ( 'should structurally share the selector' , async ( ) => {
0 commit comments