From da817fea4c9a19239f0254986a01ed3fe227df4c Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Thu, 16 Nov 2023 15:13:58 +0200 Subject: [PATCH] fix: Fix workaround for arrays that are passed as objects Amends #83. --- src/index.ts | 5 +++-- test/index.ts | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index e367dde..b29e2a3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -134,8 +134,9 @@ function normalizeArray(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]; } } } diff --git a/test/index.ts b/test/index.ts index 4798986..f6f0990 100644 --- a/test/index.ts +++ b/test/index.ts @@ -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();