1

I want to stub the entire axios object using sinon. My axios call is like

const response = await axios({
      method,
      url,
      headers,
      data,
});

I have found out that if my call was like

const response = await axios.get(url, data);

Then I could stub the function like

sinon.stub(axios, "post").resolves(mockResponse);

But this is not working for the axios() call, but only for axios.post().

  • 1
    This is what [moxios](https://github.com/axios/moxios) is for. Alternatively (and what I recommend), don't mock anything except for the response using [MSW](https://mswjs.io/), the fact the request is being made through axios is an implementation detail – Adam Jenkins Apr 27 '23 at 12:13

0 Answers0