ctimmerm / axios-mock-adapter

Axios adapter that allows to easily mock requests
MIT License
3.44k stars 241 forks source link

Not able to cover throw res.error, when status is 200 and response contains an error field. #320

Open KunwarVSuryavanshi opened 2 years ago

KunwarVSuryavanshi commented 2 years ago
axios
      .post(url, payload)
      .then((res) => {
        if (res.error) {
          throw res.error;  // **_THIS PART, WHERE WE HAVE ERROR AS IN RESPONSE_**
        }
        const someVar= res.data;
      })
      .catch((error) => {
        if (error.response && error.response.status === 403) {
         do something here...
        } else {
          do something else here...
        }
      });

For the above code even after defining res as :- const mockData = { error: { response: { message: "Some error caught :/", status: 403 } } } And passing it to mock.onPost().reply(200,mockData); That line is not getting covered.