create-react-app: Jest test pass but I always get a “Nothing was returned from render” error when running jest coverage

Note: I used create-react-app to create a new App, but I got an error I cant fix, I already looked through similar questions; the solutions provided do not solve my problem.

I am getting the following error in my React app: console.error node_modules/jsdom/lib/jsdom/virtual-console.js:29 <br> Error: Uncaught [Error: Test(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.]

My Jest plug dependencies:

"@testing-library/jest-dom": "^5.11.0",
"@testing-library/react": "^10.4.6",
"@testing-library/user-event": "^12.0.11",
"babel-eslint": "10.1.0",
    "babel-jest": "^24.9.0",
    "babel-loader": "8.1.0",
    "babel-plugin-named-asset-import": "^0.3.6",
    "babel-preset-react-app": "^9.1.2",

I try to search reason on google and get taht maybe this issue caused by babel version, solution looks like below { "presets": [ [""@babel/preset-react"", { "pragma": "React.createElement" }] ] }

but we use babel-preset-react-app, so could you help advise how to resolve this issue?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 6
  • Comments: 23 (2 by maintainers)

Commits related to this issue

Most upvoted comments

I updated my CRA project with yarn add --exact react-scripts@3.4.3 and I still cannot run coverage. Using react-scripts test --env=jest-environment-jsdom-sixteen --coverage I have empty coverage table/report. With --coverage --watchAll I have the same problem as is described above (a lot of errors with these variables vs without flags all tests are passed).

The same issue happens with react-scripts@4.0.0

having created a fresh CRA today, and coming across this issue, I downgraded from 3.4.3 to 3.4.0 yarn add --exact react-scripts@3.4.0 and now it seems to work.

PRs are welcome. I don’t know which comments it could be. I doubt it is related to Testing Library’s comments.

I’d suggest anyone with this issue try the alpha version of react-scripts and see if the issue still exists. I have a feeling it’ll be fixed.