![](/img/trans.png)
[英][function].apply() causing “JScript object expected” error in IE
[英]How to apply expect over softAssertAll or show explicity in the test result that the softAssertAll passed (Error: Expected Object to be a function)
我正在使用“soft-assert”库( soft-assert library )在我的测试步骤上应用断言,如果其中任何一个失败,则不会停止测试。
根据文档,在测试结束时使用 softAssertAll() 命令验证所有软断言。 这很好用。 但是,如果没有失败,我在测试结果中看不到任何明确的消息,就像我使用 expect 命令时一样。
所以,我试图在 softAssertAll() 命令上应用 expect,如下所示,但我收到错误消息: “expected { Object (userInvocationStack, specWindow, ...) } to be a function”
我正在尝试做的事情:
expect(cy.softAssertAll()).not.throw(Error)
有谁知道我该怎么做或解决下图中的错误? 提前致谢。
请参阅 Chai 示例中的throw
var badFn = function () { throw new TypeError('Illegal salmon!'); };
expect(badFn).to.throw();
请注意,您传入函数名称而不调用它。 我认为这允许 chai 将函数调用包装在 try-catch 中并优雅地报告失败。
您不能对 Cypress 自定义命令执行相同操作,因为它不会像上面的badFn
那样引发错误。 在内部,它会吞下任何错误并将测试状态设置为“失败”。
您可以合理地期望这会起作用
expect(jsonAssertion.softAssertAll).not.throw()
但是jsonAssertion
中有一个内部错误,似乎与它的类中的this
引用有关。
TypeError:无法读取未定义的属性(读取“_softThrowJsonDiffArray”)
要修复,请使用箭头函数
const testSoftAssertAll = () => jsonAssertion.softAssertAll();
expect(testSoftAssertAll).not.throw()
或更短
expect(() => jsonAssertion.softAssertAll()).not.throw()
这更干净更清晰
// expect all soft-assert to be passing
expect(jsonAssertion.jsonDiffArray).to.eq(undefined)
// expect first soft-assert to fail with a certain message
expect(jsonAssertion.jsonDiffArray[0].error.message).to.contain('Illegal salmon')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.