axios-mock-adapter icon indicating copy to clipboard operation
axios-mock-adapter copied to clipboard

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

Open notKvS opened this issue 3 years ago • 0 comments

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.

notKvS avatar Nov 02 '21 08:11 notKvS