使用测试库 findby* 查询和 @badeball/cypress-cucumber-preprocessor

old*_*eyg 0 cucumber cypress cypress-cucumber-preprocessor cypress-testing-library

我有一个反应应用程序,我正在尝试使用 Cypress 进行测试,badeball/cypress-cucumber-preprocessortesting-library出现错误

cy.findByRole is not a function
Run Code Online (Sandbox Code Playgroud)

这是我当前的设置:

  • 反应脚本:5.0.1
  • 打字稿:4.8.3
  • 柏树:10.8.0
  • @badeball/cypress-黄瓜-预处理器:12.2.0
  • @testing-library/cypress:8.0.3
  • 节点:16.15.0

我创建了一个示例应用程序来演示这里的问题

的 e2e 部分cypress.config.ts有两种配置,可以通过注释掉一种并保留另一种来进行测试。第一个(当前配置的)将尝试将测试作为功能文件运行,但会失败。第二个配置使用正常的 cypress 测试,并将显示“testing-library”功能在那里正常工作。

setupNodeEvents()中的函数并不cypress.config.ts完全遵循 badeball/cypress-cucumber-preprocessor 文档中找到的 webpack/ts 示例,因为该示例与 esModuleInterop 设置为 true 时效果不佳,该值在我的应用程序的其他部分中使用,因此此配置这是我为实现这一目标所做的尝试。但我确实测试了该示例配置,但仍然无法使测试库功能正常工作。

我已经设置了脚本,因此您可以使用npm test在 e2e 模式下启动 cypress。

任何帮助表示赞赏。

Ala*_*paz 5

@Tiana 是正确的,但此外您已经supportFile: false在配置中进行了设置,因此您的导入support/commands.ts将永远不会被使用。

赛普拉斯.config.ts

export default defineConfig({
  ...
  e2e: {
    specPattern: "**/*.feature",

    supportFile: false,        <-- don't do this if you want to use the support file
    setupNodeEvents,
  },
});
Run Code Online (Sandbox Code Playgroud)