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 snapshot testing passing unique classNames #916

Closed
corbanbrook opened this issue Jun 13, 2017 · 3 comments
Closed

Jest snapshot testing passing unique classNames #916

corbanbrook opened this issue Jun 13, 2017 · 3 comments

Comments

@corbanbrook
Copy link

Styled components generate a unique classname hash based on the style content and passes this classname to the snapshot. This causes snapshots to break when styles are adjusted.

I understand this might be useful if you want to break snapshots on style change or even show style diffs with the jest-styled-components plugin but by including the hashed classname it ends up not only breaking the snapshot of the changed component but also the snapshots of any components that wrap it. This can be a mild annoyance when adjusting a Button styling causes hundreds of snapshots all over the application to break because they included Button.

CSS Modules had a similar issue but solved it with the identity-obj-proxy lib and moduleNameMapper:

    "moduleNameMapper": {
      "\\.(css)$": "identity-obj-proxy"
     }

which would convert className={styles.myStyle} to className="myStyle" in the snapshot rather than "myStyle-{unique-hash}".

Is there something similar for mocking in classnames for styled-components?

@kitten
Copy link
Member

kitten commented Jun 13, 2017

This should be opened over at jest-styled-components rather than here :)

@k15a
Copy link
Member

k15a commented Jun 13, 2017

I've moved it over to jest-styled-components styled-components/jest-styled-components#29

@kitten
Copy link
Member

kitten commented Jun 13, 2017

Cheers :)

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

No branches or pull requests

3 participants