question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A way to disable Cypress global exception handler

See original GitHub issue

It would be nice to turn off the Cypress global exception handler per test. For example, we have our own exception handler that sends the errors to the remote crash reporting server. We could write an e2e test to make sure it works as expected. We can stub the server route and then raise an error in the window’s context on purpose.

cy.window()
        .then(win => {
          function raise () {
            throw new Error(`E2E test error`)
          }
          win.setTimeout(raise, 100)
        })
        .wait('@error')

The route is working, but the Cypress own crash handler thinks this error was unhandled and fails the test. If we could turn the Cypress crash handler just for this test, it would make a lot of sense.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
brian-manncommented, Apr 6, 2017

Right now its possible to “hack” this by severing Cypress’s ability to detect uncaught errors like this:

cy.visit("/app", {
  onBeforeLoad: (win) => {
    win.onerror = null
  }
})

or simply by doing…

Cypress.Cy.prototype.onUncaughtException = function(){}
1reaction
brian-manncommented, Jan 9, 2018

It’s part of a different error message than that one which redirect you here:

https://docs.cypress.io/api/events/catalog-of-events.html#Uncaught-Exceptions

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress Uncaught Assertion Error despite cy ... - Stack Overflow
The easiest way to fix this is to add the following to the top of your spec: ... To turn off all uncaught...
Read more >
Catalog of Events - Cypress Documentation
Description: Fires when your app calls the global window.alert() method. ... To conditionally turn off uncaught exception handling for a certain error.
Read more >
How to handle Errors in Cypress | BrowserStack
Error handling is essential to avoid false failed tests. Learn different ways of Cypress Error and Exception Handling techniques with this ...
Read more >
Handle Service Unavailable and Uncaught Exception in ...
In this video, I have explained how to solve handle service unavailable error and Uncaught Exception in Cypress.To handle Service ...
Read more >
Filtering app errors in Cypress tests - YouTube
This video shows how Cypress catches exceptions thrown from the ... Then it shows how to register the error handler for all tests....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found