Build issue during Jest tests when importing react-children-utilities
See original GitHub issueDescribe the bug Importing any file from react-children-utilities results in a build error when running the jest test suite.
D:\new-create-react-app\node_modules\react-children-utilities\react-children-utilities.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { Children } from 'react';
^
SyntaxError: Unexpected token {
3 | import './App.css';
4 |
> 5 | import { deepMap } from 'react-children-utilities';
| ^
6 |
7 | function App() {
8 | return (
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
at Object.<anonymous> (src/App.js:5:1)
I am unclear whether this issue exists in react-children-utilities
or whatever it is a configuration problem with jest
, but a default installation of create-react-app
also results in this issue. Builds etc are fine, only the jest test is broken.
There are various tickets https://github.com/facebook/jest/issues/6229 discussing this problem, however none of the suggestions work for this particular library.
To Reproduce Steps to reproduce the behavior:
- Install a new project from https://github.com/facebook/create-react-app (
npx create-react-app my-app
) - Eject the application (
yarn eject
) - At this point running
yarn run test
should pass all tests yarn add react-children-utilities
- Update
/src/App.js
to import anything fromreact-children-utilities
, for example:import { deepMap } from 'react-children-utilities';
- At this point running
yarn run test
will fail with the above error.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Test Utilities - React
ReactTestUtils makes it easy to test React components in the testing framework of your choice. At Facebook we use Jest for painless JavaScript...
Read more >Continuous integration for React applications using Jest and ...
First, you need to import the App component, but the only export in App.js is the Redux -connected version of the component: export...
Read more >React & Jest, how to test changing state and checking for ...
Figured it out! Did not need React Test Utilities it('should render the Notification component if state.error is true', ...
Read more >React app testing: Jest and React Testing Library
Here, the test case is provided by Jest. For rendering and accessing the virtual DOM, we import and use both render and screen...
Read more >React Unit Testing Using Enzyme and Jest - Toptal
Therefore, one of the best ways to avoid creating legacy code is using test-driven development (TDD). While there are many tools available to...
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
This issues still persist, i have run into this problem and spent couple of days already in search of the answer. I have i guess tried all the possible options given on this page and other github pages, no luck 😦.
Yes, after doing the
yarn eject
it will be there.OK, I tried again with
create-react-app
I did two things.
1 - Added the ignore in package.json jest config
2 - Created a babel.config.js in the root folder with the content
Those two steps made the tests pass