Skip to content

Commit

Permalink
fix: Fix workaround for arrays that are passed as objects (#238)
Browse files Browse the repository at this point in the history
Amends #83.
  • Loading branch information
orgads committed Nov 16, 2023
1 parent 2e4e702 commit 6e2454a
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 @@ -137,8 +137,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, 10);
if (!Number.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 6e2454a

Please sign in to comment.