Used SVG as a ReactComponent and during the jest test getting this error:
SyntaxError: corner-resize-arrow.svg: Support for the experimental syntax 'jsx' isn't currently enabled (1:1):
<svg width="12" height="12" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg'
<path d=-"M12 8.58307e-05L3.05176e-05 12L3.1209e-05 9L9
8.51393e-05L12 8.58307e-05Z" fill="white"/>
<path d="M6 5.34058e-05L-4.76837e-06 5.99988L-4.5538e-06 2.99988L3
5.31912e-05L6 5.34058e-05z" fill="white"/>
</svg>
Add @babel/preset-react (https://git.io/IfeDR) to the 'presets' section of your
Babel config to enable transformation.
If you want to leave it as-is, add @babel/plugin-syntax-isx
(https://git.io/vb4yA) to the 'plugins' section to enable parsing,
But I already have @babel/preset-react in my config file.
module.exports = {
"presets": ['@babel/preset-env', '@babel/preset-react'],
"plugins": ['@babel/plugin-proposal-class-properties']
}
Here is the jest config inside pckage.json file.
"jest": {
"verbose": true,
"collectCoverage": true,
"collectCoverageFrom":[
"**/src/**"
"!**/node_modules/**",
"!**/src/index**",
"!**/src/const**"
"!**/src/Redux/constants**"
"!**/coverage/**"
"!**/public/**"
"!**/tests/**"
"!**/webpack/**",
"!**/babel.config.js**"
"!**/src/serviceWorker.js**"
],
"coverageReporters": [
"lcov"
"text"
"clover"
"json"
],
"coverageDirectory":"./coverage",
"setupFiles": [
"./src/setupTests.js"
],
"moduleFileExtensions": [
"js",
"jsx"
],
"moduleNameMapper": {
"'\(ess|less|scss|sass)$": "identity-obj-proxy"
},
"testResultsProcessor":"jest-sonar-reporter"
}
Note: NPM start command works fine.
CodePudding user response:
Your presets
in the babel config is missing the @
for the preset-env
entry:
module.exports = {
"presets": ['@babel/preset-env', '@babel/preset-react'],
"plugins": ['@babel/plugin-proposal-class-properties']
}
CodePudding user response:
If you don't have babel-jest
installed in your project, you will need to add it. npm install --save-dev babel-jest
could do the trick if you use NPM as your package manager.
It is automatically detected and used by Jest.