question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Functional components lose displayName when running coverage

See original GitHub issue

Description

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:

  1. npm ls react-scripts (if you haven’t ejected): UNMET PEER DEPENDENCY eslint-plugin-import@2.0.1
  2. node -v: v6.9.1
  3. npm -v: 3.10.9

Then, specify:

  1. Operating system: OSX Sierra 10.12
  2. Browser and version: Safari 10.0

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
wyzecommented, Jan 6, 2017

This is fixed as of babel-plugin-istanbul@3.1.2. I just did a fresh project with create-react-app and was able to use npm 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 to Component, but this still passes when checking coverage.

// Works
const Hello = () => <div>Hello</div>

export default Hello

// Doesn't work
export default () => <div>Hello</div>
1reaction
gaearoncommented, Jan 6, 2017

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 running npm install again.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found