尝试使用Enzyme v3对我的React应用程序进行单元测试,但没有用。 PFB详情:
安装的模块:
"enzyme": "^3.1.1",
"enzyme-adapter-react-15.4": "^1.0.5",
创建了一个文件 enzyme.config.js :
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-15.4';
Enzyme.configure({ adapter: new Adapter() });
将上述文件包含在我的业力转轮中:
files: [
// test setup
...........
'test/unit/testutils/enzyme.config.js',
..........
]
出现以下错误:
14 11 2017 16:21:48.962:INFO [PhantomJS 2.1.1 (Windows 7 0.0.0)]: Connected on socket GWRhv0qSSmqs4UrpAAAC with id 5625410
PhantomJS 2.1.1 (Windows 7 0.0.0) ERROR
SyntaxError: Use of reserved word 'import'
at test/unit/testutils/enzyme.config.js:1
我有什么遗漏的吗?
答案 0 :(得分:0)
{
"presets": ["es2015", "react"],
"plugins": [
"transform-es2015-modules-commonjs"
]
}
karma.conf:
module.exports = function (config) {
config.set({
preprocessors: {
'src/**/*.js': ['babel'],
'test/**/*.js': ['babel']
},
babelPreprocessor: {
options: {
presets: ['env'],
sourceMap: 'inline'
},
...