Cypress测试失败是由于应用程序代码错误而不是我的代码错误。我试图通过使用下面的代码来绕过该错误,但仍然无法正常工作。我可以看到Cypress团队在Github中打开了类似的错误,但是有人可以提供解决方法(如果有)?
on('uncaught:exception', (err, runnable) => {
return false
})
答案 0 :(得分:0)
来自https://github.com/cypress-io/cypress/issues/987:
[Cypress没有在
top.onerror
上具有处理程序,仅在规范iframe和应用iframe上具有处理程序,并且某些错误会直接冒到顶部。
作为解决方法,您可以将其添加到规范文件或support/index.js
的顶部:
// ignore uncaught exceptions
Cypress.on('uncaught:exception', (err) => {
return false
})
// patch Cypress top.onerror
Object.defineProperty(top, 'onerror', {
value: window.onerror,
})