我已经阅读过,src/setupTests.js应该在每个测试之前加载,但我仍然遇到了每个测试都失败的错误:
这是我的src/setupTests.js文件:"Enzyme Internal Error: Enzyme expects an adapter to be configured, but found none."
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 16 和 react-scripts 2.1.1
有没有人能看出我做错了什么?
npm install
。这算是重新启动测试运行器吗?在这种情况下,测试运行器到底是什么? - Travisnpm run test
(或npm test
)就可以解决问题了,但我现在看到这个问题已经得到了答复。 - David