ctimmerm / axios-mock-adapter

Axios adapter that allows to easily mock requests
MIT License
3.47k stars 245 forks source link

axios.CancelToken is waiting for delay specified in delayResponse #258

Open chestozo opened 4 years ago

chestozo commented 4 years ago

Hi there! First of all - thank you for a great tool! )

I am using MockAdapter in storybook environment during development phase. I have a form where I am performing server field validation. For that to look more real I am using a combination of:

const apiMock = new MockAdapter(axiosInstance, { delayResponse: 5000 })
const token = axios.CancelToken.source()
//...
token.cancel('Operation cancelled')

In real app token.cancel will lead to an almost instant reaction of a request been aborted. While in my case with a MockAdapter I need to wait for the 5000ms to complete and only after that I get a request failure.

What do you think of an option to abort request immediately based on axios.CancelToken?

ctimmerm commented 4 years ago

Yeah, that makes sense. delayResponse should not affect canceling a request.

imsunhao commented 3 years ago

hello Is there a plan to solve this problem now? I've also encountered this problem.