我已经读到src / setupTests.js应该在每次测试之前加载,但是我仍然让每个测试失败并显示以下错误:
“酶内部错误:酶希望配置适配器,但找不到。”
这是我的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脚本2.1.1的React 16上
我做错了任何人都可以看到的吗?
最佳答案
当您将以下内容添加到package.json时是否有效
"scripts": {
...
"test": "react-scripts test",
...
}