Closed rnemec closed 5 years ago
Requests can be resolved out of order by providing the second parameter to the mockResponse
or mockError
methods.
In the latest version I've added the lastReqGet
which can be used to fetch the internal queue data item, which contains all the info regarding the request made.
If you store this object in you spec script you can use it to resolve previous requests in any order. The data contained in the object can be used to determine the contents of each request.
Does this help?
I bump into same problem. i have 4 API calls in ComponentDidMount and i want to control the response of each. lastReqGet doesn't help me.
This is probably a feature request: If the module I'm testing makes multiple
axios
calls, could the dev have more control for mocking responses based on request data? I guess if the calls order is guaranteed, your API still works (I like the queue approach you did) but if they are done e.g. using Promise.all or some other less predictable ways, I wonder what you could offer. 😄