@@ -14,8 +14,8 @@ describe("Exponential Backoff Error Handler", function () {
14
14
defaults : { headers : { post : { } } } ,
15
15
interceptors : {
16
16
response : { use : jest . fn ( ) , handlers : [ ] } ,
17
- request : { use : jest . fn ( ) }
18
- }
17
+ request : { use : jest . fn ( ) } ,
18
+ } ,
19
19
} ) ,
20
20
} ;
21
21
@@ -42,7 +42,8 @@ describe("Exponential Backoff Error Handler", function () {
42
42
const requestClient = new RequestClient ( { autoRetry : true } ) ;
43
43
44
44
// Extract error handler from axios interceptors
45
- errorHandler = requestClient . axios . interceptors . response . use . mock . calls [ 0 ] [ 1 ] ;
45
+ errorHandler =
46
+ requestClient . axios . interceptors . response . use . mock . calls [ 0 ] [ 1 ] ;
46
47
axiosInstance = requestClient . axios ;
47
48
} ) ;
48
49
@@ -77,14 +78,14 @@ describe("Exponential Backoff Error Handler", function () {
77
78
retryableError . config = {
78
79
method : "GET" ,
79
80
url : "/test" ,
80
- retryCount : 0
81
+ retryCount : 0 ,
81
82
} ;
82
83
83
84
// Setup axios mock to resolve on retry
84
85
jest . spyOn ( axiosInstance , "request" ) . mockResolvedValueOnce ( {
85
86
status : 200 ,
86
87
data : "success" ,
87
- headers : { }
88
+ headers : { } ,
88
89
} ) ;
89
90
90
91
// Start the retry process
@@ -101,14 +102,14 @@ describe("Exponential Backoff Error Handler", function () {
101
102
expect . objectContaining ( {
102
103
method : "GET" ,
103
104
url : "/test" ,
104
- retryCount : 1
105
+ retryCount : 1 ,
105
106
} )
106
107
) ;
107
108
108
109
expect ( result ) . toEqual ( {
109
110
status : 200 ,
110
111
data : "success" ,
111
- headers : { }
112
+ headers : { } ,
112
113
} ) ;
113
114
} ) ;
114
115
@@ -118,14 +119,14 @@ describe("Exponential Backoff Error Handler", function () {
118
119
retryableError . config = {
119
120
method : "GET" ,
120
121
url : "/test" ,
121
- retryCount : 0
122
+ retryCount : 0 ,
122
123
} ;
123
124
124
125
// Setup axios mock to resolve on retry
125
126
jest . spyOn ( axiosInstance , "request" ) . mockResolvedValueOnce ( {
126
127
status : 200 ,
127
128
data : "success" ,
128
- headers : { }
129
+ headers : { } ,
129
130
} ) ;
130
131
131
132
// Start the retry process
@@ -142,14 +143,14 @@ describe("Exponential Backoff Error Handler", function () {
142
143
expect . objectContaining ( {
143
144
method : "GET" ,
144
145
url : "/test" ,
145
- retryCount : 1
146
+ retryCount : 1 ,
146
147
} )
147
148
) ;
148
149
149
150
expect ( result ) . toEqual ( {
150
151
status : 200 ,
151
152
data : "success" ,
152
- headers : { }
153
+ headers : { } ,
153
154
} ) ;
154
155
} ) ;
155
156
@@ -159,14 +160,14 @@ describe("Exponential Backoff Error Handler", function () {
159
160
retryableError . config = {
160
161
method : "GET" ,
161
162
url : "/test" ,
162
- retryCount : 0
163
+ retryCount : 0 ,
163
164
} ;
164
165
165
166
// Setup axios mock to resolve on retry
166
167
jest . spyOn ( axiosInstance , "request" ) . mockResolvedValueOnce ( {
167
168
status : 200 ,
168
169
data : "success" ,
169
- headers : { }
170
+ headers : { } ,
170
171
} ) ;
171
172
172
173
// Start the retry process
@@ -183,14 +184,14 @@ describe("Exponential Backoff Error Handler", function () {
183
184
expect . objectContaining ( {
184
185
method : "GET" ,
185
186
url : "/test" ,
186
- retryCount : 1
187
+ retryCount : 1 ,
187
188
} )
188
189
) ;
189
190
190
191
expect ( result ) . toEqual ( {
191
192
status : 200 ,
192
193
data : "success" ,
193
- headers : { }
194
+ headers : { } ,
194
195
} ) ;
195
196
} ) ;
196
197
@@ -200,7 +201,7 @@ describe("Exponential Backoff Error Handler", function () {
200
201
retryableError . config = {
201
202
method : "GET" ,
202
203
url : "/test" ,
203
- retryCount : 0
204
+ retryCount : 0 ,
204
205
} ;
205
206
206
207
// First retry fails again with same error
@@ -209,16 +210,17 @@ describe("Exponential Backoff Error Handler", function () {
209
210
secondError . config = {
210
211
method : "GET" ,
211
212
url : "/test" ,
212
- retryCount : 1
213
+ retryCount : 1 ,
213
214
} ;
214
215
215
216
// Setup axios mock to fail on first retry, then succeed
216
- jest . spyOn ( axiosInstance , "request" )
217
+ jest
218
+ . spyOn ( axiosInstance , "request" )
217
219
. mockRejectedValueOnce ( secondError )
218
220
. mockResolvedValueOnce ( {
219
221
status : 200 ,
220
222
data : "success finally" ,
221
- headers : { }
223
+ headers : { } ,
222
224
} ) ;
223
225
224
226
// Start the retry process
@@ -242,7 +244,7 @@ describe("Exponential Backoff Error Handler", function () {
242
244
expect . objectContaining ( {
243
245
method : "GET" ,
244
246
url : "/test" ,
245
- retryCount : 1
247
+ retryCount : 1 ,
246
248
} )
247
249
) ;
248
250
@@ -251,14 +253,14 @@ describe("Exponential Backoff Error Handler", function () {
251
253
expect . objectContaining ( {
252
254
method : "GET" ,
253
255
url : "/test" ,
254
- retryCount : 2
256
+ retryCount : 2 ,
255
257
} )
256
258
) ;
257
259
258
260
expect ( result ) . toEqual ( {
259
261
status : 200 ,
260
262
data : "success finally" ,
261
- headers : { }
263
+ headers : { } ,
262
264
} ) ;
263
265
} ) ;
264
266
@@ -277,13 +279,14 @@ describe("Exponential Backoff Error Handler", function () {
277
279
error3 . config = { method : "GET" , url : "/test" , retryCount : 2 } ;
278
280
279
281
// Setup axios mock for sequence of calls
280
- jest . spyOn ( axiosInstance , "request" )
282
+ jest
283
+ . spyOn ( axiosInstance , "request" )
281
284
. mockRejectedValueOnce ( error2 )
282
285
. mockRejectedValueOnce ( error3 )
283
286
. mockResolvedValueOnce ( {
284
287
status : 200 ,
285
288
data : "success" ,
286
- headers : { }
289
+ headers : { } ,
287
290
} ) ;
288
291
289
292
// Mock setTimeout to capture delay values
@@ -299,7 +302,7 @@ describe("Exponential Backoff Error Handler", function () {
299
302
await retryPromise ;
300
303
301
304
// Extract the delays from the setTimeout calls
302
- const delays = setTimeoutSpy . mock . calls . map ( call => call [ 1 ] ) ;
305
+ const delays = setTimeoutSpy . mock . calls . map ( ( call ) => call [ 1 ] ) ;
303
306
304
307
// Verify exponential backoff pattern (with some flexibility due to jitter)
305
308
expect ( delays [ 0 ] ) . toBeLessThanOrEqual ( 200 ) ; // ~100 * 2^1 with jitter
@@ -315,19 +318,20 @@ describe("Exponential Backoff Error Handler", function () {
315
318
// Create a client with custom max retries
316
319
const customClient = new RequestClient ( {
317
320
autoRetry : true ,
318
- maxRetries : 2
321
+ maxRetries : 2 ,
319
322
} ) ;
320
323
321
324
// Extract error handler
322
- const customErrorHandler = customClient . axios . interceptors . response . use . mock . calls [ 0 ] [ 1 ] ;
325
+ const customErrorHandler =
326
+ customClient . axios . interceptors . response . use . mock . calls [ 0 ] [ 1 ] ;
323
327
324
328
// Create an error that's already at the retry limit
325
329
const finalRetryError = new Error ( "Final retry" ) ;
326
330
finalRetryError . code = "ECONNRESET" ;
327
331
finalRetryError . config = {
328
332
method : "GET" ,
329
333
url : "/test" ,
330
- retryCount : 2 // Already at the max retry limit
334
+ retryCount : 2 , // Already at the max retry limit
331
335
} ;
332
336
333
337
try {
@@ -344,19 +348,20 @@ describe("Exponential Backoff Error Handler", function () {
344
348
const customClient = new RequestClient ( {
345
349
autoRetry : true ,
346
350
maxRetryDelay : 150 , // Very low max delay
347
- maxRetries : 5
351
+ maxRetries : 5 ,
348
352
} ) ;
349
353
350
354
// Extract error handler
351
- const customErrorHandler = customClient . axios . interceptors . response . use . mock . calls [ 0 ] [ 1 ] ;
355
+ const customErrorHandler =
356
+ customClient . axios . interceptors . response . use . mock . calls [ 0 ] [ 1 ] ;
352
357
353
358
// Create an error for a high retry count (which would normally have a long delay)
354
359
const highRetryError = new Error ( "High retry count" ) ;
355
360
highRetryError . code = "ECONNRESET" ;
356
361
highRetryError . config = {
357
362
method : "GET" ,
358
363
url : "/test" ,
359
- retryCount : 4 // Would normally be 100 * 2^4 = 1600ms
364
+ retryCount : 4 , // Would normally be 100 * 2^4 = 1600ms
360
365
} ;
361
366
362
367
// Mock setTimeout to capture delay value
@@ -366,7 +371,7 @@ describe("Exponential Backoff Error Handler", function () {
366
371
jest . spyOn ( customClient . axios , "request" ) . mockResolvedValueOnce ( {
367
372
status : 200 ,
368
373
data : "success" ,
369
- headers : { }
374
+ headers : { } ,
370
375
} ) ;
371
376
372
377
// Start the retry process
@@ -386,4 +391,4 @@ describe("Exponential Backoff Error Handler", function () {
386
391
expect ( delay ) . toBeLessThanOrEqual ( 150 ) ;
387
392
} ) ;
388
393
} ) ;
389
- } ) ;
394
+ } ) ;
0 commit comments