Enzyme setup error: "Jest encountered an unexpected token"

144 Views Asked by At

I have a problem setting up enzyme on a project using react-16 as front-end

I've got this error when I try to test

enter image description here

Here is my package.json

"devDependencies": {
    "@babel/plugin-proposal-class-properties": "^7.7.4",
    "@babel/preset-react": "^7.0.0",
    "axios": "^0.19",
    "babel-plugin-syntax-class-properties": "^6.13.0",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "cross-env": "^5.1",
    "react": "^16.2.0"
},
"dependencies": {
    "@babel/core": "^7.6.4",
    "@babel/preset-env": "^7.6.3",
    "babel-cli": "^6.26.0",
    "babel-jest": "^24.9.0",
    "babel-loader": "^8.0.6",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "enzyme": "^3.10.0",
    "enzyme-adapter-react-16": "^1.15.1",
    "jest": "^24.9.0",
    "raf": "^3.4.1",
    "react-bootstrap": "^1.0.0-beta.14",
    "react-dates": "^21.5.0",
    "react-dom": "^16.11.0",
    "react-modal": "^3.11.1",
    "react-redux": "^7.1.3",
    "react-router-dom": "^5.1.2",
    "react-test-renderer": "^16.12.0",
    "react-toolbox": "^2.0.0-beta.13",
    "redux": "^4.0.4",
  }

Test config file test.config.json

{
    "testRegex": "((\\.|/*.)(test))\\.js?$",
    "setupFilesAfterEnv": [
        "<rootDir>/app/resources/js/test/setupTests.js"
    ]
}

Setut test config file setupTests.js

import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

Enzyme.configure({
    adapter: new Adapter()
});
1

There are 1 best solutions below

0
On

I found my problem. I reinstalled this packages

npm install @babel/core babel-loader @babel/preset-env @babel/preset-react @babel/plugin-proposal-class-properties @babel/plugin-proposal-object-rest-spread

For testing I used PhpStorm so I had to add config file into the Jest options