1 回答
TA贡献1839条经验 获得超15个赞
您可以使用 Cypress 拦截控制台消息cy.spy(),但如果您想进一步了解数据 - 我还没有看到任何方法可以做到这一点。
该文档可以使用一点再治具,所以这里就是我如何设置的间谍。
let spy;
Cypress.on('window:before:load', (win) => {
spy = cy.spy(win.console, "error") // can be other methods - log, warn, etc
})
it('Doing something that should not cause a console error', () => {
// Run test steps here that may cause a console error
cy.wait(100).then(x => {
expect(spy).not.to.be.called
})
// or perhaps this, to auto-retry (have not tried this syntax)
cy.wrap({}).should(() => {
expect(spy).not.to.be.called
})
// The docs imply you can just do this
expect(spy).not.to.be.called
// ..but that line may run before any other cy command above finish
// so I'd stick with using cy.wrap({}).then(...) to put it in the command chain
// The spy call count is reset after each test
})
添加回答
举报