【发布时间】:2019-05-07 15:07:17
【问题描述】:
我已经读到 src/setupTests.js 应该在每次测试之前加载,但我仍然让每个测试都失败并出现错误:
“Enzyme 内部错误:Enzyme 需要配置适配器,但没有找到。”
这是我的 src/setupTests.js
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import 'whatwg-fetch';
Enzyme.configure({ adapter: new Adapter() });
这是我的 package.json:
"devDependencies": {
"babel-core": "^6.26.3",
"babel-jest": "^23.6.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"coveralls": "^3.0.2",
"enzyme": "^3.7.0",
"enzyme-adapter-react-16": "^1.6.0",
"enzyme-to-json": "^3.3.4",
"jest": "^23.6.0",
"react-test-renderer": "^16.5.2",
"redux-mock-store": "^1.5.3",
"regenerator-runtime": "^0.12.1",
"whatwg-fetch": "^3.0.0"
}
我正在通过npm run test 运行“测试”脚本
"scripts": {
"test": "jest",
"test:watch": "jest --watch",
"test:updateSnapshots": "jest --updateSnapshot"
}
我用以下某种形式开始每个测试文件:
import React from 'react';
import { shallow } from 'enzyme';
我正在使用 react-scripts 2.1.1 使用 React 16
我是否做错了任何人都能看到的事情?
【问题讨论】:
-
您是否尝试重新启动测试运行器?这与我的工作设置几乎相同。
-
@DeveloperDavo 我已经删除了我的 node_modules 文件夹并
npm installed 多次。这算作重新启动我的测试运行器吗?在这种情况下,测试运行器到底是什么? -
间接:)。重新运行
npm run test(或npm test)可以解决问题,但我现在看到问题已经得到解答。
标签: reactjs jestjs enzyme create-react-app babel-jest