SyntaxError: using the reserved word import of an enzyme with karma

Testing my React app with Enzyme v3 did not help. PFB:

Modules installed

:

"enzyme": "^3.1.1", "enzyme-adapter-react-15.4": "^1.0.5", 

Created the file ferse.config.js :

 import Enzyme from 'enzyme'; import Adapter from 'enzyme-adapter-react-15.4'; Enzyme.configure({ adapter: new Adapter() }); 

Included above file in my karma runner conf:

 files: [ // test setup ........... 'test/unit/testutils/enzyme.config.js', .......... ] 

Received the 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 can't see?

0
reactjs requirejs gruntjs karma-runner enzyme
source share
1 answer

Do you use babel? You must, in one way, use the babel register before running the tests, and use the following .babelrc file: (set 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' }, ... 
0
source share

All Articles