Cypress 原因:属性 'each' 在类型 'TestFunction' 上不存在

Cypress causes: Property 'each' does not exist on type 'TestFunction'

我们在项目中引入了 cypress 9.3.1 进行端到端测试。现在我们面临的问题是我们现有的 jest 测试无法在 CI.

中编译

所有参数化测试都出现以下错误:

Property 'each' does not exist on type 'TestFunction'.
       it.each<TestCase>([

问题:如何解决?


我们尝试过但没有奏效的方法:

刚刚 运行 也解决了这个问题,结果发现我们的 tsconfig.json 中包含了来自 mocha 的冲突类型定义。确保您没有加载 Mocha 的类型定义。

编辑:我们最终需要做的是为我们的柏树测试创建一个单独的 tsconfig.json,如下所述:https://docs.cypress.io/guides/tooling/typescript-support#Configure-tsconfig-json

我们按照 here 所述使用 tsconfig.json(请参阅@JRJurman 回答),但这在我们的项目中不起作用。

现在我们使用的是 cypress-each 插件,由一位 cypress 贡献者开发。

npm i -D cypress-each

用法:

import 'cypress-each'

// create a separate test for each selector
const selectors = ['header', 'footer', '.new-todo']
it.each(selectors)('element %s is visible', (selector) => {
  cy.visit('/')
  cy.get(selector).should('be.visible')
})