我在使用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"
]
}
Setut测试配置文件 setupTests.js
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
Enzyme.configure({
adapter: new Adapter()
});
答案 0 :(得分: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选项