@@ -249,7 +249,10 @@ describe('queryObserver', () => {
249249 test ( 'should always run the selector again if selector throws an error and selector is not referentially stable' , async ( ) => {
250250 const key = queryKey ( )
251251 const results : QueryObserverResult [ ] = [ ]
252- const queryFn = ( ) => ( { count : 1 } )
252+ const queryFn = async ( ) => {
253+ await sleep ( 10 )
254+ return { count : 1 }
255+ }
253256 const observer = new QueryObserver ( queryClient , {
254257 queryKey : key ,
255258 queryFn,
@@ -260,10 +263,10 @@ describe('queryObserver', () => {
260263 const unsubscribe = observer . subscribe ( result => {
261264 results . push ( result )
262265 } )
263- await sleep ( 1 )
266+ await sleep ( 50 )
264267 await observer . refetch ( )
265268 unsubscribe ( )
266- expect ( results . length ) . toBe ( 4 )
269+ expect ( results . length ) . toBe ( 5 )
267270 expect ( results [ 0 ] ) . toMatchObject ( {
268271 status : 'loading' ,
269272 isFetching : true ,
@@ -284,6 +287,11 @@ describe('queryObserver', () => {
284287 isFetching : false ,
285288 data : undefined ,
286289 } )
290+ expect ( results [ 4 ] ) . toMatchObject ( {
291+ status : 'error' ,
292+ isFetching : false ,
293+ data : undefined ,
294+ } )
287295 } )
288296
289297 test ( 'should return stale data if selector throws an error' , async ( ) => {
@@ -293,7 +301,11 @@ describe('queryObserver', () => {
293301 const error = new Error ( 'select error' )
294302 const observer = new QueryObserver ( queryClient , {
295303 queryKey : key ,
296- queryFn : ( ) => ( shouldError ? 2 : 1 ) ,
304+ retry : 0 ,
305+ queryFn : async ( ) => {
306+ await sleep ( 10 )
307+ return shouldError ? 2 : 1
308+ } ,
297309 select : num => {
298310 if ( shouldError ) {
299311 throw error
@@ -306,11 +318,11 @@ describe('queryObserver', () => {
306318 const unsubscribe = observer . subscribe ( result => {
307319 results . push ( result )
308320 } )
309- await sleep ( 10 )
321+ await sleep ( 50 )
310322 await observer . refetch ( )
311323 unsubscribe ( )
312324
313- expect ( results . length ) . toBe ( 4 )
325+ expect ( results . length ) . toBe ( 5 )
314326 expect ( results [ 0 ] ) . toMatchObject ( {
315327 status : 'loading' ,
316328 isFetching : true ,
@@ -335,6 +347,12 @@ describe('queryObserver', () => {
335347 data : '1' ,
336348 error,
337349 } )
350+ expect ( results [ 4 ] ) . toMatchObject ( {
351+ status : 'error' ,
352+ isFetching : false ,
353+ data : '1' ,
354+ error,
355+ } )
338356 } )
339357
340358 test ( 'should structurally share the selector' , async ( ) => {
0 commit comments