4

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
})
2
  • Not sure if you're referring to this issue or another one, but I've seen they've described some workaround in this one couple of weeks ago. Maybe try it out if you haven't yet: github.com/cypress-io/cypress/issues/987 Commented Oct 14, 2019 at 8:37
  • I am following the same thread and the workaround provided in the thread is not working in my case Commented Oct 15, 2019 at 6:29

1 Answer 1

3

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,
})
Sign up to request clarification or add additional context in comments.

1 Comment

We also can add if (err.message.includes('Expected error')) { return false } to be more assertive

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.