Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
notKvS opened this issue Nov 2, 2021 · 0 comments

Comments

@notKvS
Copy link

notKvS commented Nov 2, 2021

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 notKvS changed the title Not able to cover throw.error, when status is 200 and response contains an error field. Not able to cover throw res.error, when status is 200 and response contains an error field. Nov 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant