File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
packages/toolkit/src/query Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ const retryWithBackoff: BaseQueryEnhancer<
83
83
5 ,
84
84
( ( defaultOptions as any ) || EMPTY_OPTIONS ) . maxRetries ,
85
85
( ( extraOptions as any ) || EMPTY_OPTIONS ) . maxRetries ,
86
- ] . filter ( Boolean )
86
+ ] . filter ( x => x !== undefined )
87
87
const [ maxRetries ] = possibleMaxRetries . slice ( - 1 )
88
88
89
89
const defaultRetryCondition : RetryConditionFunction = ( _ , __ , { attempt } ) =>
Original file line number Diff line number Diff line change @@ -439,6 +439,33 @@ describe('configuration', () => {
439
439
expect ( baseBaseQuery ) . toHaveBeenCalledTimes ( 4 )
440
440
} )
441
441
442
+ test ( 'Specifying maxRetries as 0 in RetryOptions prevents retries' , async ( ) => {
443
+ const baseBaseQuery = jest . fn <
444
+ ReturnType < BaseQueryFn > ,
445
+ Parameters < BaseQueryFn >
446
+ > ( )
447
+ baseBaseQuery . mockResolvedValue ( { error : 'rejected' } )
448
+
449
+ const baseQuery = retry ( baseBaseQuery , { maxRetries : 0 } )
450
+ const api = createApi ( {
451
+ baseQuery,
452
+ endpoints : ( build ) => ( {
453
+ q1 : build . query ( {
454
+ query : ( ) => { } ,
455
+ } ) ,
456
+ } ) ,
457
+ } )
458
+
459
+ const storeRef = setupApiStore ( api , undefined , {
460
+ withoutTestLifecycles : true ,
461
+ } )
462
+
463
+ storeRef . store . dispatch ( api . endpoints . q1 . initiate ( { } ) )
464
+ await loopTimers ( 2 )
465
+
466
+ expect ( baseBaseQuery ) . toHaveBeenCalledTimes ( 1 )
467
+ } ) ;
468
+
442
469
test . skip ( 'RetryOptions only accepts one of maxRetries or retryCondition' , ( ) => {
443
470
// @ts -expect-error Should complain if both exist at once
444
471
const ro : RetryOptions = {
You can’t perform that action at this time.
0 commit comments