Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cypress test failing due to error in Application Code

Tags:

cypress

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
})
like image 662
Jatinderpal Singh Avatar asked Oct 18 '25 05:10

Jatinderpal Singh


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,
})
like image 55
bkucera Avatar answered Oct 21 '25 15:10

bkucera