Ahm*_*m23 5 javascript timeout cypress
我的问题是,我希望 Cypress 库的期望断言有一个超时,但似乎无法找到这样做的方法。
我尝试大大增加 cypress.conf 中的全局超时;然而,这不起作用。
if ($widget.find('report-widget')) {
SVGCount++;
expect(barGraphsChange[index]).to.not.equal(undefined)
console.log(barGraphsChange, index)
cy.getBarGraphTotal(SVGCount, barGraphsChange[index])
}
Run Code Online (Sandbox Code Playgroud)
如果不是超时,那么合理的解决方法也很好,谢谢!
另请注意:在此阶段之前,barGraphsChange[index] 正在通过调用的自定义 Cypress 命令进行计算和分配。
小智 7
您可以使用 自定义您的期望should(),这将自动重试指定超时或全局 defaultCommandTimeout(如果未提供)的断言。在你的情况下,我可能可以想象包装你的对象,指定超时,然后将你的逻辑传递给应该:
cy.wrap(someFunction, {timeout: 25000}).should(someFunction => expect(someFunction()).to.eq(someValue))
Run Code Online (Sandbox Code Playgroud)
在这里阅读更多信息:https ://docs.cypress.io/api/commands/should.html#Function