Functional components lose displayName when running coverage
See original GitHub issueDescription
Coverage fails to run tests correctly, resulting in failed tests that are actually passing when run without --coverage
.
Expected behavior
Passing tests should still pass when i add --coverage
Actual behavior
Tests that are passing without --coverage
are failing when i add --coverage
.
Environment
Run these commands in the project folder and fill in their results:
npm ls react-scripts
(if you haven’t ejected): UNMET PEER DEPENDENCY eslint-plugin-import@2.0.1node -v
: v6.9.1npm -v
: 3.10.9
Then, specify:
- Operating system: OSX Sierra 10.12
- Browser and version: Safari 10.0
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
how to set displayName in a functional component [React]
React either needs displayName for functional components when they're defined as arrow functions, or the name of the function itself.
Read more >mobx-react-component - npm
Write React functional components (with hooks) + MobX for local state in a fancy way. ... Start using mobx-react-component in your project by...
Read more >React.js displayName - GeeksforGeeks
The displayName string is used in debugging messages. It's usually not necessary to set it explicitly because the name of the function or ......
Read more >Tooling - styled-components
Control the components displayName By default, the displayName of a component will be prefixed with the filename in order to make the component...
Read more >The Guide to Learning React Hooks (Examples & Tutorials)
Hooks bring to functional components the things we once were only able to do ... The side-by-side below shows how the component has...
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 is fixed as of
babel-plugin-istanbul@3.1.2
. I just did a fresh project withcreate-react-app
and was able to usenpm test -- --coverage
successfully.Note that
displayName
is only set when you define your component and use that variable as the default export. If you follow the 2nd example, the displayName isn’t set and defaults toComponent
, but this still passes when checking coverage.Awesome, thanks for reporting back. Closing this.
I sent a PR to Jest to enforce a minimal version in the future, but for now existing users can get the fix by removing
node_modules
and runningnpm install
again.