Skip to content

Commit 9e45c72

Browse files
committed
chore: run prettier
1 parent dd578fa commit 9e45c72

File tree

1 file changed

+38
-33
lines changed

1 file changed

+38
-33
lines changed

spec/unit/base/ExponentialBackoffErrorHandler.spec.js

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ describe("Exponential Backoff Error Handler", function () {
1414
defaults: { headers: { post: {} } },
1515
interceptors: {
1616
response: { use: jest.fn(), handlers: [] },
17-
request: { use: jest.fn() }
18-
}
17+
request: { use: jest.fn() },
18+
},
1919
}),
2020
};
2121

@@ -42,7 +42,8 @@ describe("Exponential Backoff Error Handler", function () {
4242
const requestClient = new RequestClient({ autoRetry: true });
4343

4444
// 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];
4647
axiosInstance = requestClient.axios;
4748
});
4849

@@ -77,14 +78,14 @@ describe("Exponential Backoff Error Handler", function () {
7778
retryableError.config = {
7879
method: "GET",
7980
url: "/test",
80-
retryCount: 0
81+
retryCount: 0,
8182
};
8283

8384
// Setup axios mock to resolve on retry
8485
jest.spyOn(axiosInstance, "request").mockResolvedValueOnce({
8586
status: 200,
8687
data: "success",
87-
headers: {}
88+
headers: {},
8889
});
8990

9091
// Start the retry process
@@ -101,14 +102,14 @@ describe("Exponential Backoff Error Handler", function () {
101102
expect.objectContaining({
102103
method: "GET",
103104
url: "/test",
104-
retryCount: 1
105+
retryCount: 1,
105106
})
106107
);
107108

108109
expect(result).toEqual({
109110
status: 200,
110111
data: "success",
111-
headers: {}
112+
headers: {},
112113
});
113114
});
114115

@@ -118,14 +119,14 @@ describe("Exponential Backoff Error Handler", function () {
118119
retryableError.config = {
119120
method: "GET",
120121
url: "/test",
121-
retryCount: 0
122+
retryCount: 0,
122123
};
123124

124125
// Setup axios mock to resolve on retry
125126
jest.spyOn(axiosInstance, "request").mockResolvedValueOnce({
126127
status: 200,
127128
data: "success",
128-
headers: {}
129+
headers: {},
129130
});
130131

131132
// Start the retry process
@@ -142,14 +143,14 @@ describe("Exponential Backoff Error Handler", function () {
142143
expect.objectContaining({
143144
method: "GET",
144145
url: "/test",
145-
retryCount: 1
146+
retryCount: 1,
146147
})
147148
);
148149

149150
expect(result).toEqual({
150151
status: 200,
151152
data: "success",
152-
headers: {}
153+
headers: {},
153154
});
154155
});
155156

@@ -159,14 +160,14 @@ describe("Exponential Backoff Error Handler", function () {
159160
retryableError.config = {
160161
method: "GET",
161162
url: "/test",
162-
retryCount: 0
163+
retryCount: 0,
163164
};
164165

165166
// Setup axios mock to resolve on retry
166167
jest.spyOn(axiosInstance, "request").mockResolvedValueOnce({
167168
status: 200,
168169
data: "success",
169-
headers: {}
170+
headers: {},
170171
});
171172

172173
// Start the retry process
@@ -183,14 +184,14 @@ describe("Exponential Backoff Error Handler", function () {
183184
expect.objectContaining({
184185
method: "GET",
185186
url: "/test",
186-
retryCount: 1
187+
retryCount: 1,
187188
})
188189
);
189190

190191
expect(result).toEqual({
191192
status: 200,
192193
data: "success",
193-
headers: {}
194+
headers: {},
194195
});
195196
});
196197

@@ -200,7 +201,7 @@ describe("Exponential Backoff Error Handler", function () {
200201
retryableError.config = {
201202
method: "GET",
202203
url: "/test",
203-
retryCount: 0
204+
retryCount: 0,
204205
};
205206

206207
// First retry fails again with same error
@@ -209,16 +210,17 @@ describe("Exponential Backoff Error Handler", function () {
209210
secondError.config = {
210211
method: "GET",
211212
url: "/test",
212-
retryCount: 1
213+
retryCount: 1,
213214
};
214215

215216
// Setup axios mock to fail on first retry, then succeed
216-
jest.spyOn(axiosInstance, "request")
217+
jest
218+
.spyOn(axiosInstance, "request")
217219
.mockRejectedValueOnce(secondError)
218220
.mockResolvedValueOnce({
219221
status: 200,
220222
data: "success finally",
221-
headers: {}
223+
headers: {},
222224
});
223225

224226
// Start the retry process
@@ -242,7 +244,7 @@ describe("Exponential Backoff Error Handler", function () {
242244
expect.objectContaining({
243245
method: "GET",
244246
url: "/test",
245-
retryCount: 1
247+
retryCount: 1,
246248
})
247249
);
248250

@@ -251,14 +253,14 @@ describe("Exponential Backoff Error Handler", function () {
251253
expect.objectContaining({
252254
method: "GET",
253255
url: "/test",
254-
retryCount: 2
256+
retryCount: 2,
255257
})
256258
);
257259

258260
expect(result).toEqual({
259261
status: 200,
260262
data: "success finally",
261-
headers: {}
263+
headers: {},
262264
});
263265
});
264266

@@ -277,13 +279,14 @@ describe("Exponential Backoff Error Handler", function () {
277279
error3.config = { method: "GET", url: "/test", retryCount: 2 };
278280

279281
// Setup axios mock for sequence of calls
280-
jest.spyOn(axiosInstance, "request")
282+
jest
283+
.spyOn(axiosInstance, "request")
281284
.mockRejectedValueOnce(error2)
282285
.mockRejectedValueOnce(error3)
283286
.mockResolvedValueOnce({
284287
status: 200,
285288
data: "success",
286-
headers: {}
289+
headers: {},
287290
});
288291

289292
// Mock setTimeout to capture delay values
@@ -299,7 +302,7 @@ describe("Exponential Backoff Error Handler", function () {
299302
await retryPromise;
300303

301304
// 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]);
303306

304307
// Verify exponential backoff pattern (with some flexibility due to jitter)
305308
expect(delays[0]).toBeLessThanOrEqual(200); // ~100 * 2^1 with jitter
@@ -315,19 +318,20 @@ describe("Exponential Backoff Error Handler", function () {
315318
// Create a client with custom max retries
316319
const customClient = new RequestClient({
317320
autoRetry: true,
318-
maxRetries: 2
321+
maxRetries: 2,
319322
});
320323

321324
// 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];
323327

324328
// Create an error that's already at the retry limit
325329
const finalRetryError = new Error("Final retry");
326330
finalRetryError.code = "ECONNRESET";
327331
finalRetryError.config = {
328332
method: "GET",
329333
url: "/test",
330-
retryCount: 2 // Already at the max retry limit
334+
retryCount: 2, // Already at the max retry limit
331335
};
332336

333337
try {
@@ -344,19 +348,20 @@ describe("Exponential Backoff Error Handler", function () {
344348
const customClient = new RequestClient({
345349
autoRetry: true,
346350
maxRetryDelay: 150, // Very low max delay
347-
maxRetries: 5
351+
maxRetries: 5,
348352
});
349353

350354
// 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];
352357

353358
// Create an error for a high retry count (which would normally have a long delay)
354359
const highRetryError = new Error("High retry count");
355360
highRetryError.code = "ECONNRESET";
356361
highRetryError.config = {
357362
method: "GET",
358363
url: "/test",
359-
retryCount: 4 // Would normally be 100 * 2^4 = 1600ms
364+
retryCount: 4, // Would normally be 100 * 2^4 = 1600ms
360365
};
361366

362367
// Mock setTimeout to capture delay value
@@ -366,7 +371,7 @@ describe("Exponential Backoff Error Handler", function () {
366371
jest.spyOn(customClient.axios, "request").mockResolvedValueOnce({
367372
status: 200,
368373
data: "success",
369-
headers: {}
374+
headers: {},
370375
});
371376

372377
// Start the retry process
@@ -386,4 +391,4 @@ describe("Exponential Backoff Error Handler", function () {
386391
expect(delay).toBeLessThanOrEqual(150);
387392
});
388393
});
389-
});
394+
});

0 commit comments

Comments
 (0)