Not able to test error states with Cypress
See original GitHub issueI have followed below link to setup miragejs with Cypress.
https://miragejs.com/quickstarts/cypress/setup
Issue: Setup doesn’t work for error responses.
When I add below code in my test.
/* skipping this test for now becuase miragjs,
doesn't return error response as expected. */
server.del('/users/1', () => {
return new Response(400, {}, { message: 'Invalid input' });
});
I actually receive below response in my application code (My application is using plain fetch
, no axios
).
To my surprise response from fetch has status as 200
but has payload as my error response.
{"type":"default","status":200,"ok":true,"statusText":"OK","headers":{"map":{"content-type":"application/json"}},"url":"https://localhost:3030/stores/1","_bodyInit":"{\"message\":\"Invalid input\"}","_bodyText":"{\"message\":\"Invalid input\"}"}
Can someone help me to solve this, I am blocked.
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (3 by maintainers)
Top Results From Across the Web
Error Messages | Cypress Documentation
This message means that Cypress was unable to find tests in the specified file. You'll likely get this message if you have an...
Read more >Cypress : how can I fail a test if an error occurs but only at the ...
I have already seen these answers ==> Cypress: Is it possible to complete a test after failure, Denial of Service (status code 429)...
Read more >Cypress and Flaky Tests: How to Handle Timeout Errors
Asynchronous operations are not completing before Cypress runs a command, causing a timeout error. Flaky Cypress Tests Caused by Timeout Errors.
Read more >How to handle Errors in Cypress | BrowserStack
An Exception or an Error is an abnormal event, which may break the normal flow of test script execution, in turn causing the...
Read more >Fixing Cypress cross-origin errors - Reflect.run
The reason why Cypress historically has not been able to test across domains is because since it operates inside the browser runtime, ...
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
@asantos00 Thanks a lot !! for your quick fix. Your fix just works great !!
Following up from my previous comment, I managed to get this working by keeping a reference of the Response class on Cypress and using that for my error codes. Here is my code:
cypress/support/index.js
src/mirage/setup-cypress-passthrough.js
cypress/integration/home.spec.js