I know this has been asked countless times, but I am not able to fix the problem inspite of following all the SO solutions and suggestions.
I came to know about jest
a few days ago and tried to have my hands on it. There is a good tutorial mentioned on DZone about using jest
to test react components. However, when I try testing one of the components from the starter
directory, I am having this issue,
SyntaxError: Unexpected token import
at ScriptTransformer._transformAndBuildScript (../../../../../../usr/local/lib/node_modules/jest/node_modules/jest-runtime/build/ScriptTransformer.js:289:17) at emitTwo (events.js:106:13)
As per suggested in this SO post, I have already installed babel-preset-react
and added it to my webpack.config.js
file.
Here is my webpack.config.js
file, my package.json
file , the .babelrc
file
Please note that I have already gone through the solutions posted in these SO posts -
which might be apparent from the changes in my .babelrc
and webpack
files
But I'm not able to fix the issue that I'm having. Please let me know if I am missing something here, since I have spent a good 3-4 hrs searching SO and other forums for any answer and I can't seem to find it.
Update 1: Here is my test file - Clock.test.jsx
import React from 'react';
import ReactDOM from 'react-dom';
import Clock from 'Clock';
describe('Clock',()=>{
it("renders without crashing",()=>{
const div = document.createElement('div');
ReactDOM.render(<Clock/>,div);
});
});