SyntaxError:使用保留字'import'运行酶与业力 [英] SyntaxError: Use of reserved word 'import' running enzyme with karma
本文介绍了SyntaxError:使用保留字'import'运行酶与业力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
试用Enzyme v3测试我的React应用程序没有奏效。 PFB的详细信息:
模块安装:
酶: ^ 3.1.1,
enzyme-adapter-react-15.4:^ 1.0.5,
创建一个文件 enzyme.config.js :
import Enzyme from 酶;
从'enzyme-adapter-react-15.4'导入适配器;
Enzyme.configure({adapter:new Adapter()});
将以上文件包含在我的业力运行者conf中:
文件:[
//测试设置
...........
'test / unit / testutils / enzyme.config.js',
..........
]
出现以下错误:
14 11 2017 16:21:48.962:INFO [PhantomJS 2.1.1(Windows 7 0.0.0)]:在套接字GWRhv0qSSmqs4UrpAAAC上连接,ID为5625410
PhantomJS 2.1.1(Windows 7 0.0.0)错误
语法错误:使用保留字'import'
at test / unit / testutils / enzyme.config.js:1
有什么我不见了?
解决方案
您是否使用babel?在运行测试之前,您应该使用babel-register,并使用以下.babelrc文件:(安装它的依赖项)
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'
},
...
Tried unit testing my React application with Enzyme v3, did not work. PFB the details:
modules installed:
"enzyme": "^3.1.1",
"enzyme-adapter-react-15.4": "^1.0.5",
Created a file enzyme.config.js:
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-15.4';
Enzyme.configure({ adapter: new Adapter() });
Included the above file in my karma runner conf:
files: [
// test setup
...........
'test/unit/testutils/enzyme.config.js',
..........
]
Got following error:
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
Is there anything I am missing?
解决方案
Are you using babel? You should, one way would be using babel-register before runing the tests, and use the following .babelrc file: (install its dependencies)
{
"presets": ["es2015", "react"],
"plugins": [
"transform-es2015-modules-commonjs"
]
}
Or install karma-babel-preprocessor
karma.conf:
module.exports = function (config) {
config.set({
preprocessors: {
'src/**/*.js': ['babel'],
'test/**/*.js': ['babel']
},
babelPreprocessor: {
options: {
presets: ['env'],
sourceMap: 'inline'
},
...
这篇关于SyntaxError:使用保留字'import'运行酶与业力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文