Cypress test failing due to error in Application Code

Viewed 5182

Cypress tests are failing due to application code error and not my code error. I have tried to bypass the error by using below code, but still it does not work. I can see similar bug is open in Github by Cypress team but someone can please provide a workaround, if any?

on('uncaught:exception', (err, runnable) => {

  return false
})
1 Answers

From https://github.com/cypress-io/cypress/issues/987:

[Cypress doesn't] have a handler on top.onerror, only on the spec iframe and app iframe, and some errors will bubble straight to top.

As a workaround, you can add this to the top of your spec file or support/index.js:


// ignore uncaught exceptions
Cypress.on('uncaught:exception', (err) => {
  return false
})

// patch Cypress top.onerror
Object.defineProperty(top, 'onerror', {
  value: window.onerror,
})
Related