Closed mario128mex closed 3 years ago
I just found out the issue, I needed to await the retry call on my test here
describe('node-retry test issue', () => {
it('should throw and error when the max amount of attempts is reached', async () => {
const mockAxiosError = {
isAxiosError: true,
config: {
url: 'bad-site.com',
method: 'get'
},
response: {
status: 500,
statusText: 'some weird error',
data: {
Error: 'Mock error!'
}
}
}
const mockApiCall = jest
.fn()
.mockRejectedValueOnce(mockAxiosError)
.mockRejectedValueOnce(mockAxiosError)
.mockRejectedValueOnce(mockAxiosError)
.mockRejectedValueOnce(mockAxiosError)
.mockRejectedValueOnce(mockAxiosError)
try {
await retry(() => mockApiCall(), APICallRetryerOptions)
} catch (err) {
expect(err.isAxiosError).toBeTruthy()
expect(err.response.data.Error).toEqual('Mock error!')
}
expect(mockApiCall).toHaveBeenCalledTimes(5)
})
})
Hi I have the following code
retryer.js
then I run this code which send a 404 on purpose main.js
the retryer behaves as expected
but in my tests when I pass a mocked function that always returns a rejected promise, the retryer only do one call and then exits, why is this? retryer.test.js
the above code, as I said before, calls mockAPICall once and then exits, I've tried to debug the test to see why that happens but I could figure it out, also I've done some research but I couldn't find a similar issue
I also tried to change
mockAPICall
declaration toconst mockApiCall = jest.fn(() => Promise.reject(mockAxiosError))
but still getting just one callcan you point out what I'm doing wrong? Thanks!