Unable to run Jest tests when running under create-react-app
See original GitHub issueWhen trying to run Jest tests under create react app with yarn test
I get the following error:
● Test suite failed to run
/projects/project/node_modules/jsoneditor-react/es/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import React, { Component } from 'react';
^^^^^^
SyntaxError: Cannot use import statement outside a module
2 | import { Button, Col, Row, Container } from "reactstrap";
3 |
> 4 | import { JsonEditor as Editor } from "jsoneditor-react";
| ^
5 | import "jsoneditor-react/es/editor.min.css";
6 |
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
The code compiles just fine without any errors and works as intended. Somehow running it with NODE_ENV=test causes the transpiler to fail.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
'Failed to initialize watch plugin' when running tests for newly ...
Describe the bug Running tests (using npm test) for a newly created app throws the error: Error: Failed to initialize watch plugin ...
Read more >Running Tests | Create React App
Jest is a Node-based runner. This means that the tests always run in a Node environment and not in a real browser.
Read more >Jest test not passing in create react app - Stack Overflow
My create-react-app (es6) with redux builds and runs in the browser as expected. I think there is something wrong with my imports in...
Read more >Testing Environments - React
This document goes through the factors that can affect your environment and recommendations for some scenarios. Test runners. Test runners like Jest, mocha, ......
Read more >Cannot run Jest tests with create-react-app fork - YouTrack
First, I thought that it was due to one of our customizations. So I took the plain create-react-app source and just published the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@lepinkainen here’s what I used:
package.json:
stub.js:
transformIgnorePatterns did not work for me.
Had to use: moduleNameMapper: { “jsoneditor-react”: a file with empty stub }