How to mock reject reponse with status > 400
See original GitHub issueHow to mock reject reponse with status > 400 . I want to mock errorneous response i.g.
moxios.wait(() => {
const request = moxios.requests.mostRecent();
request.respondWith({
status: 422,
response: { message: 'problem' },
});
});
How can I do it?
Issue Analytics
- State:
- Created 7 years ago
- Comments:8
Top Results From Across the Web
SuperTest / JEST , how to force or mock a 400 status code?
Mock find method of Thought model to reject with an error in your test. First, import the model in your test and automock...
Read more >Mocking error responses - Recipes - Mock Service Worker Docs
Here's an example on how to mock an error response for the login POST request: ... 8 // Send a valid HTTP status...
Read more >How to mock requests for unit testing in Node - freeCodeCamp
If you really need to test HTTP-specific code, and the response from the external API is relatively simple, use Nock, and manually mock...
Read more >How to Mock API Calls in Test Environments - Stoplight Blog
Returns a 200 status with a users posts when requested · Request: {method:'get',body:{user:“Jack”}} · Response: {status:200,posts:posts:[“I just ...
Read more >Successfully Throwing Async Errors with the Jest Testing Library
There's only one situation developers want errors to happen, and that's in specific tests ... Next, I tried to mock a rejected value...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I manage to do it via following :-
Thanks for this lib.
For anyone using
stubRequest
you should be able to just use a non 2XX status:@Sutikshan it looks like
respondWith
does this as well. Here it callsaxois.settle
which as you can see here rejects for invalid response statuses. Not sure why it wasn’t working for you.