首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在ReactJS缺少库模块中进行单元测试时出错

在ReactJS缺少库模块中进行单元测试时出错
EN

Stack Overflow用户
提问于 2022-11-27 21:45:34
回答 1查看 13关注 0票数 0

我正在使用ReactJs & Node为一个类编写一个测试网站,并且在运行测试时遇到了困难。我已经尝试通过npm安装重新安装软件包。升级和降级到某些版本的“测试-库”,但这会导致更多失败的测试,我尝试过安装npm助手/助手。

这是我的package.json

代码语言:javascript
复制
{
  "name": "landingpage-react-template",
  "private": true,
  "dependencies": {
    "@testing-library/react": "^9.3.2",
    "axios": "^0.27.2",
    "bcrypt": "^5.0.1",
    "bcryptjs": "^2.4.3",
    "cors": "^2.8.5",
    "database.js": "^0.0.1",
    "detect-file": "^1.0.0",
    "detect-libc": "^2.0.1",
    "emailjs-com": "^2.6.4",
    "express": "^4.18.1",
    "express-fileupload": "^1.4.0",
    "express-handlebars": "^6.0.6",
    "multer": "^1.4.5-lts.1",
    "mv": "^2.1.1",
    "mysql": "^2.18.1",
    "mysql2": "^2.3.3",
    "nodemailer": "^6.8.0",
    "react": "^17.0.1",
    "react-cookie": "^4.1.1",
    "react-dom": "^17.0.1",
    "react-router-dom": "^6.3.0",
    "react-scripts": "^5.0.1",
    "react-youtube": "^9.0.1",
    "sequelize": "^6.23.2",
    "sequelize-cli": "^6.5.1",
    "smooth-scroll": "^16.1.3"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/user-event": "^14.4.3",
    "@wojtekmaj/enzyme-adapter-react-17": "^0.6.7",
    "enzyme": "^3.11.0"
  }
}

这是运行npm测试后的错误。

代码语言:javascript
复制
 FAIL  src/pages/components/resetPasswordPage/resetPasswordComponent.test.jsx
  ● Test suite failed to run

    Cannot find module '@testing-library/dom/dist/helpers.js' from 'node_modules/@testing-library/user-event/dist/cjs/utils/misc/getWindow.js'

    Require stack:
      node_modules/@testing-library/user-event/dist/cjs/utils/misc/getWindow.js
      node_modules/@testing-library/user-event/dist/cjs/utils/dataTransfer/Clipboard.js
      node_modules/@testing-library/user-event/dist/cjs/event/behavior/click.js
      node_modules/@testing-library/user-event/dist/cjs/event/dispatchEvent.js
      node_modules/@testing-library/user-event/dist/cjs/document/prepareDocument.js
      node_modules/@testing-library/user-event/dist/cjs/setup/setup.js
      node_modules/@testing-library/user-event/dist/cjs/setup/index.js
      node_modules/@testing-library/user-event/dist/cjs/index.js
      src/pages/components/resetPasswordPage/resetPasswordComponent.test.jsx

      at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:324:11)
      at Object.<anonymous> (node_modules/@testing-library/user-event/dist/cjs/utils/misc/getWindow.js:5:18)
EN

回答 1

Stack Overflow用户

发布于 2022-11-27 21:50:57

@testing-library/dom是一个对等依赖 of user-event,需要在您的项目中单独安装。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74594019

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档