目标是如果停止任何测试的Cypress运行程序失败,这些Mocha测试是用TypeScript编写的。以下摩卡afterEach()
有两个问题..。
/// <reference types="Cypress" />
afterEach(() => {
if (this.currentTest.state === 'failed' &&
this.currentTest._currentRetry === this.currentTest._retries) {
Cypress.runner.stop();
}
});
以下是问题所在:
this.currentTest.*
>>>指的是this
>>>>>> TS2339: Property 'runner' does not exist on type 'Cypress'
我如何在TypeScript中解决这个问题,并使用// @ts-ignore
忽略它?
谢谢,谢谢你的帮助。
发布于 2020-12-31 12:03:31
是的,你可以使用// @ts-忽略。此外,您还需要使用正则函数() {}语法,而不是lambda“fat箭头”语法() => {}。
参考Cypress文档:https://docs.cypress.io/guides/core-concepts/variables-and-aliases.html#Avoiding-the-use-of-this
如果您在测试或钩子中使用箭头函数,则使用此属性访问别名的
将无法工作。这就是为什么我们的所有示例都使用正则函数() {}语法,而不是lambda“fat箭头”语法() => {}。
代码将如下所示
afterEach(function() {
if (this.currentTest.state === 'failed' &&
//@ts-ignore
this.currentTest._currentRetry === this.currentTest._retries) {
//@ts-ignore
Cypress.runner.stop();
}
});
https://stackoverflow.com/questions/65515293
复制相似问题