Closed nguyenhoanglam closed 3 months ago
Agreed +1 to fix this
This works as intended 🤔
import axios from 'axios'
import MockAdapter from 'axios-mock-adapter'
const mock = new MockAdapter(axios)
mock.onPost('/something').reply(200, {foo: 'bar'})
mock.onPost('/somethingelse').reply(200, {foo: 'bar'})
await axios.post('/something')
console.log('first request', mock.history.post[0].url)
mock.resetHistory()
await axios.post('/somethingelse')
console.log('second request', mock.history.post[0].url)
output:
first request /something
second request /somethingelse
Remember to always reference the same axios instance you're using.
If you mock the main instance, it won't intercept child instances create using axios.create()
Here is my test code
I expect
post.length
should be 1 but received 0. It looks like the mock doest not record any api call after callingresetHistory
. Any help please?