File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
packages/toolkit/src/query/tests Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -339,4 +339,36 @@ describe('configuration', () => {
339
339
340
340
expect ( baseBaseQuery ) . toHaveBeenCalledTimes ( 9 )
341
341
} )
342
+
343
+ test ( 'accepts a custom retryCondition fn' , async ( ) => {
344
+ const baseBaseQuery = jest . fn <
345
+ ReturnType < BaseQueryFn > ,
346
+ Parameters < BaseQueryFn >
347
+ > ( )
348
+ baseBaseQuery . mockResolvedValue ( { error : 'rejected' } )
349
+
350
+ const overrideMaxRetries = 3
351
+
352
+ const baseQuery = retry ( baseBaseQuery , {
353
+ maxRetries : 0 ,
354
+ retryCondition : ( _ , __ , { attempt} ) => attempt <= overrideMaxRetries ,
355
+ } )
356
+ const api = createApi ( {
357
+ baseQuery,
358
+ endpoints : ( build ) => ( {
359
+ q1 : build . query ( {
360
+ query : ( ) => { } ,
361
+ } ) ,
362
+ } ) ,
363
+ } )
364
+
365
+ const storeRef = setupApiStore ( api , undefined , {
366
+ withoutTestLifecycles : true ,
367
+ } )
368
+ storeRef . store . dispatch ( api . endpoints . q1 . initiate ( { } ) )
369
+
370
+ await loopTimers ( )
371
+
372
+ expect ( baseBaseQuery ) . toHaveBeenCalledTimes ( overrideMaxRetries + 1 )
373
+ } )
342
374
} )
You can’t perform that action at this time.
0 commit comments