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

toHaveStyleRule is not compatible with some displayNames if fileName is used #403

Closed
kamaltmo opened this issue Mar 11, 2022 · 0 comments · Fixed by #404
Closed

toHaveStyleRule is not compatible with some displayNames if fileName is used #403

kamaltmo opened this issue Mar 11, 2022 · 0 comments · Fixed by #404

Comments

@kamaltmo
Copy link
Contributor

kamaltmo commented Mar 11, 2022

Hello everyone!

We have recently tried to upgrade to v7 and styled-components v5 and this has resulted in some of our tests that use the toHaveStyleRule function to fail. The issue seems to be that we use babel-plugin-styled-components and our files are written in snake case, this leads to displayName like the following input-wrapper__InputWrapper for a file like input-wrapper.jsx with a component of InputWrapper. Styled-components then appends this to the componentId of sc-slq835-0 which results in a className of input-wrapper__InputWrapper-sc-slq835-0.

The current regex used for classNames is ^(\w+(-|_))?sc- this would correctly identify wrapper__InputWrapper-sc-slq835-0 but fails on our className due to the snakecase.

I propose we change this regex to check more generically for any string starting with sc- or containing -sc-, for example: (_|-)*sc-.+

kamaltmo added a commit to kamaltmo/jest-styled-components that referenced this issue Mar 11, 2022
kamaltmo added a commit to kamaltmo/jest-styled-components that referenced this issue Mar 11, 2022
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

Successfully merging a pull request may close this issue.

1 participant