Skip to content

Commit

Permalink
fix: Fix workaround for arrays that are passed as objects
Browse files Browse the repository at this point in the history
  • Loading branch information
orgads committed Nov 16, 2023
1 parent 5d1451c commit da817fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ function normalizeArray<T>(object?: T[]): T[] | undefined {

if (typeof object === 'object') {
for (const key of Object.keys(object)) {
if (typeof key === 'number') {
array[key] = object[key];
const num = parseInt(key);
if (!isNaN(num)) {
array[num] = object[key];
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ describe('retry-axios', () => {
}
});

it('should support methods passed as an object', async () => {
const scopes = [
nock(url).post('/').reply(500),
nock(url).post('/').reply(200, 'toast'),
];
interceptorId = rax.attach();
const result = await axios.post(url, {}, {raxConfig: {httpMethodsToRetry: Object.assign({}, ['POST'])}});
assert.strictEqual(result.data, 'toast');
for (const s of scopes) {
s.done();
}
});

it('should not retry on a post', async () => {
const scope = nock(url).post('/').reply(500);
interceptorId = rax.attach();
Expand Down

0 comments on commit da817fe

Please sign in to comment.