Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jest --coverage causes display name to change #151

Closed
IanEdington opened this issue Aug 14, 2018 · 8 comments
Closed

jest --coverage causes display name to change #151

IanEdington opened this issue Aug 14, 2018 · 8 comments

Comments

@IanEdington
Copy link

IanEdington commented Aug 14, 2018

I get different display names for this component depending on if I run jest with --coverage or not.

const IconCircle = styled(Circle)`
  justify-content: center;

with yarn jest --env=jsdom I get ReportIssueModal__IconCircle
with yarn jest --env=jsdom --coverage I get Styled(Circle)

screen shot 2018-08-14 at 8 32 26 am

@IanEdington
Copy link
Author

I found a temporary solution by setting the displayName manually.

IconCircle.displayName = 'IconCircle';

@quantizor
Copy link
Collaborator

quantizor commented Aug 15, 2018 via email

@IanEdington
Copy link
Author

IanEdington commented Aug 16, 2018

Interesting. Thanks for explaining that. enabling SSR mode on the styled-components babel plugin doesn't seem to have an effect. This is what I'm using:

  "env": {
    "test": {
      "plugins": [
        ["babel-plugin-styled-components", {
          "ssr": true
        }],

with coverage still fails

@quantizor
Copy link
Collaborator

quantizor commented Aug 16, 2018 via email

@quantizor
Copy link
Collaborator

quantizor commented Aug 21, 2018

@IanEdington Did you by chance have time to test the above? Your babelrc would look something like this:

{
  "plugins": ["styled-components"],
  "env": {
    "test": {
        "plugins": [["styled-components", { "displayName": false }]]
     }
  }
}

@IanEdington
Copy link
Author

Thanks for following up

Yes I did. Instead of ReportIssueModal_IconCircle I get styled.div which is unfortunately not very useful for a snapshot test. It does remove the conflict between the two environments though.

@quantizor
Copy link
Collaborator

quantizor commented Aug 21, 2018 via email

@ljharb
Copy link

ljharb commented Dec 8, 2021

To be clear, the way components are named is absolutely a part of the public API - the API is everything observable - so changing them must follow semver just like anything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants