Answer the question
In order to leave comments, you need to log in
How to fix an error while installing React Jest?
I just started to understand Jest and this is not a task, at the very beginning there was an error, I can’t find a solution, I installed everything according to the docks and tutorials:
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://facebook.github.io/jest/docs/en/configuration.html
Details:
9 | describe('<App />', () => {
10 | it('should render App', () => {
> 11 | const wrapper = shallow(<App />);
| ^
12 | })
13 | })
Answer the question
In order to leave comments, you need to log in
Resolved:
I didn't read the docs carefully and used more third-party resources :)
1. added the .babelrc file
2. installed npm install --save-dev babel-preset-stage-2
3. installed babel-plugin-transform-export-extensions
4. added the config to the created file in step 1
{
"env": {
"test": {
"presets": ["env", "react", "stage-2"],
"plugins": ["transform-export-extensions"],
"only": [
"./**/*.js",
"node_modules/jest-runtime"
]
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question