Jest enzyme shallow unexpected token <
It looks like you don't have a jsx support. I see you have babel-jest
installed but do you have .babelrc
file at the root folder
{
"presets": ["es2015", "react"]
}
I was able to solve this issue by introducing the below in the .babelrc
{
"env": {
"test": {
"presets": ["env", "react", "stage-2"],
"plugins": ["transform-export-extensions"],
"only": [
"./**/*.js",
"node_modules/jest-runtime"
]
}
}
}
and installing the following dev dependencies:-
"babel-plugin-transform-export-extensions"
"enzyme-adapter-react-16"
"jest-cli"
"react-test-renderer"
This is an issue with Jest not understanding JSX export.
You can solve this issue by adding the following lines to .babelrc
file:
"env": {
"test": {
"presets": ["@babel/preset-env", "@babel/preset-react"],
"plugins": ["transform-export-extensions"],
"only": [
"./**/*.js",
"node_modules/jest-runtime"
]
}
},
And then installing babel-plugin-transform-export-extensions
.