Code Coverage with Typescript test fails

Right-clicking a test inside a *.test.tsx file and choosing "Run ... with Coverage" returns error text. But right-clicking same test and choosing "Run ..test method" passes without errors. 

Edit: Seems running test with default terminal test coverage result in same error.

yarn test --coverage

Example Code.


import React from 'react'

function App() {
return (
<h1>Hello React</h1>

export default App


import React from 'react'
import {render} from '@testing-library/react'
import App from './App'

test('renders the heading', () => {
const {getByText} = render(<App/>)
const linkElement = getByText(/Hello React/i);

Output with normal Run test

yarn run v1.22.4
$ react-scripts test
PASS src/App.test.tsx
√ renders the heading (28ms)

Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 4.667s
Ran all test suites related to changed files.

Output with Code Coverage

console.error node_modules/react-dom/cjs/react-dom.development.js:19527
The above error occurred in the <App> component:
in App (at App.test.tsx:6)

Consider adding an error boundary to your tree to customize error handling behavior.
Visit to learn more about error boundaries.

Error: App(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.

Any fix for this issue with Run with Coverage? 

1 comment
Comment actions Permalink

Please try downgrading react-scripts to 3.4.0 - see


"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"@types/jest": "^24.0.0",
"@types/node": "^12.0.0",
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.0",
"typescript": "~3.7.2"

It works fine for me when using 3.4.0 (and fails with 3.4.1 )


Please sign in to leave a comment.