DEV Community

Discussion on: The only 3 steps you need to mock an API call in Jest

Collapse
 
sebastianvaliente profile image
Sebastian Valiente

Hey Zak,

Thanks for sharing this. I have a question - apologies if it was already asked.

I have a react-redux component that makes triggers multiple Axios calls (to a 3rd party API) both within the components method and via redux actions. Is there a way to use jest mock to specifically intercept each call and have different responses for each one?

I've been struggling with this and seeing how active you are in helping others and replying has given me hope! Thanks again.

Collapse
 
zaklaughton profile image
Zak Laughton

Hey Sebastian!

Unfortunately, I don't have too much experience with testing async redux functionality, and I think some of the solution would likely depend on exactly how your calls are implemented. You should be able to mock axios in the exact same way, but it may be a little trickier to predict exactly what is going to be called and in what order.

Unfortunately, I'm not the one who will have a helpful answer for you here, but I found a few resources that may help, in case you haven't seen them yet:

Sorry I don't have a better answer, but best of luck to you in finding a solution!