我正在尝试测试我的 React 应用程序,该应用程序是使用 cypress (create-react-app) 创建的。
由于某种原因,我收到此错误:
正如你所看到的,它尝试通过 ROOT_ID 获取元素,ROOT_ID 它是一个 const:
我发现解决这个问题的方法就是在 cypress/support/index.js 上导入
导入“cypress-react-unit-test/support”;
但正如你在这里看到的:
https://github.com/cypress-io/cypress-react-unit-test
该存储库已移至官方 cypress,我找不到等效的导入。
这是我的plugins/index.js:
const findWebpack = require('find-webpack')
const webpackPreprocessor = require('@cypress/webpack-preprocessor')
/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on) => {
// find the Webpack config used by react-scripts
const webpackOptions = findWebpack.getWebpackOptions()
if (!webpackOptions) {
throw new Error('Could not find Webpack in this project ')
}
const cleanOptions = {
reactScripts: true,
}
findWebpack.cleanForCypress(cleanOptions, webpackOptions)
const options = { …Run Code Online (Sandbox Code Playgroud)