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.
App.tsx
import React from 'react'
function App() {
return (
<div>
<h1>Hello React</h1>
</div>
)
}
export default App
App.test.tsx
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);
expect(linkElement).toBeInTheDocument()
})
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 https://fb.me/react-error-boundaries 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?
Please sign in to leave a comment.
Please try downgrading
react-scriptsto3.4.0- see https://github.com/facebook/jest/issues/9723#issuecomment-643234155It works fine for me when using
3.4.0(and fails with3.4.1)