0

我在使用 react-16 作为前端的项目中设置酶时遇到问题

当我尝试测试时出现此错误

在此处输入图像描述

这是我的package.json

"devDependencies": {
    "@babel/plugin-proposal-class-properties": "^7.7.4",
    "@babel/preset-react": "^7.0.0",
    "axios": "^0.19",
    "babel-plugin-syntax-class-properties": "^6.13.0",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "cross-env": "^5.1",
    "react": "^16.2.0"
},
"dependencies": {
    "@babel/core": "^7.6.4",
    "@babel/preset-env": "^7.6.3",
    "babel-cli": "^6.26.0",
    "babel-jest": "^24.9.0",
    "babel-loader": "^8.0.6",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "enzyme": "^3.10.0",
    "enzyme-adapter-react-16": "^1.15.1",
    "jest": "^24.9.0",
    "raf": "^3.4.1",
    "react-bootstrap": "^1.0.0-beta.14",
    "react-dates": "^21.5.0",
    "react-dom": "^16.11.0",
    "react-modal": "^3.11.1",
    "react-redux": "^7.1.3",
    "react-router-dom": "^5.1.2",
    "react-test-renderer": "^16.12.0",
    "react-toolbox": "^2.0.0-beta.13",
    "redux": "^4.0.4",
  }

测试配置文件test.config.json

{
    "testRegex": "((\\.|/*.)(test))\\.js?$",
    "setupFilesAfterEnv": [
        "<rootDir>/app/resources/js/test/setupTests.js"
    ]
}

设置测试配置文件setupTests.js

import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

Enzyme.configure({
    adapter: new Adapter()
});
4

1 回答 1

0

我发现了我的问题。我重新安装了这个包

npm install @babel/core babel-loader @babel/preset-env @babel/preset-react @babel/plugin-proposal-class-properties @babel/plugin-proposal-object-rest-spread

为了进行测试,我使用了PhpStorm,所以我必须将配置文件添加到Jest 选项中

于 2019-12-13T09:25:49.470 回答