gpt4 book ai didi

尽管 cy.on ('uncaught:exception' Cypress 未捕获断言错误)

转载 作者:行者123 更新时间:2023-12-03 15:49:28 25 4
gpt4 key购买 nike

关于以下错误:

Uncaught Error: Script error.
Cypress detected that an uncaught error was thrown from a cross origin script.
We cannot provide you the stack trace, line number, or file where this error occurred.

引用 https://docs.cypress.io/api/events/catalog-of-events.html#To-catch-a-single-uncaught-exception

我正在尝试运行填写表单并单击按钮提交的测试:
it('adds biological sample with maximal input', function(){
cy.on('uncaught:exception', (err, runnable) => {
expect(err.message).to.include('of undefined')
done()
return false
});
cy.get('a').contains('Add biological sample').click();

. . .

cy.contains('Action results');
});

尽管我的规范包含以下内容,但我还是收到了错误消息:
    cy.on('uncaught:exception', (err, runnable) => {
expect(err.message).to.include('of undefined')
done()
return false
});

这是测试失败的图像 the test failing .

左下角的错误是,

Error: Uncaught AssertionError: expected '$f is not defined\n\nThis error originated from your application code, not from Cypress. \n\nWhen Cypress detects uncaught errors originating from your application it will automatically fail the current test.\n\nThis behavior is configurable, and you can choose to turn this off by listening to the \'uncaught:exception\' event.\n\nhttps://on.cypress.io/uncaught-exception-from-application' to include 'of undefined' (https://www.flukebook.org/_cypress/runner/cypress_runner.js:49186)



似乎我正在接受 Cypress 的建议并没有得到想要的结果。有什么建议?这有发生在其他人身上吗?

最佳答案

你能删除expect(err.message).to.include('of undefined')吗?和 done()从 cypress 异常块并在测试中添加以下代码并再次运行测试

Cypress.on('uncaught:exception', (err, runnable) => {
// returning false here prevents Cypress from
// failing the test
return false
})

关于尽管 cy.on ('uncaught:exception' Cypress 未捕获断言错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53845493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com