diff --git a/src/index.ts b/src/index.ts index 3f370ba..a42662f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -137,8 +137,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 number_ = Number.parseInt(key, 10); + if (!Number.isNaN(number_)) { + array[number_] = object[key]; } } } diff --git a/test/index.ts b/test/index.ts index 24f397e..f9b32f3 100644 --- a/test/index.ts +++ b/test/index.ts @@ -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();