Skip to content Skip to sidebar Skip to footer

Jest Encountered An Unexpected Token: Syntaxerror: Unexpected Token {

Issue: I am running my tests with Jest and Enzyme when I came across this error when I was running my code on a different machine. When I run npm test which only runs jest --covera

Solution 1:

I had the same problem, it is being answered in similar questions. The way I got around it was to install two class babel plugins:

npm install --save babel-plugin-transform-class-properties
npm install --save babel-plugin-syntax-class-properties

and include them in your .babelrc file:

"plugins":["transform-class-properties","syntax-class-properties"]

After restarting the tests, the error should be gone :) Good luck!

Solution 2:

Try it like this:

importEnzymefrom'enzyme';
importAdapterfrom'enzyme-adapter-react-16';

Enzyme.configure({ adapter: newAdapter() });

Solution 3:

Try to add the following plugin to your .babelrc config file in order to fix the import Enzyme error:

"plugins": ["transform-es2015-modules-commonjs"]

Post a Comment for "Jest Encountered An Unexpected Token: Syntaxerror: Unexpected Token {"