Open LukeSilva opened 6 years ago
I’m experiencing something similar, but this might be related to #17.
I’m trying to test mockResponse
with mockError
in the same suite. If I call mockResponse
first, then the first and all subsequent calls will work fine, but mockError
will err with Cannot read property 'reject' of undefined
.
The opposite is true: if I call mockError
first then try and call mockResponse
. The error call will execute fine but subsequent calls will err with Cannot read property 'resolve' of undefined
.
I’m calling mockAxios.reset()
on afterEach
every time.
Edit: the axios call I’m testing uses both .then()
and .catch()
. Code here
I'm having the same issue with jest-mock-axios
4.6.1. I've got mockAxios.reset()
being called in afterEach()
, and I've verified that it's actually being called every time. However, if I put an expect(mockAxios).not.toHaveBeenCalled()
at the beginning of one of my later test, it will fail with multiple calls from previous tests in the same file.
For me (4.5.0), adding
beforeEach(() => {
jest.clearAllMocks()
})
on top of
afterEach(() => {
mockAxios.reset()
})
works for me. Not ideal as the example snippet provided which causes confusion, but it's working.
You can call axios with code like the following: