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 731edbf commit 12517a3
Show file tree
Hide file tree
Showing 2 changed files with 20 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 number_ = Number.parseInt(key);
if (!isNaN(number_)) {
array[number_] = object[key];
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@ 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: {...['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 12517a3

Please sign in to comment.