小编Byt*_*tor的帖子

Cypress React,找不到根元素来安装组件

我正在尝试测试我的 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)

javascript testing reactjs webpack cypress

4
推荐指数
1
解决办法
4097
查看次数

标签 统计

cypress ×1

javascript ×1

reactjs ×1

testing ×1

webpack ×1