-
-
Notifications
You must be signed in to change notification settings - Fork 142
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-styled-components toHaveStyleRule()
does not detect styles when using babel-plugin-styled-components
#268
Comments
The correct behavior can be seen by removing |
Created PR #269 for a solution that makes all componentIds prefixed with |
Hello, Thanks @robilars-amazon for the PR. Any estimate on when this can be reviewed and merged ? |
Love to see this get merged soon. |
Seconded, kinda driving me crazy over here, none of the fixes or hacks seem to work for me. Can try to help if needed. |
I published out a fork of the package with the PR applied. Feel free to use this till a fix is added to master |
@robilars-amazon much appreciated, thank you! |
This is still not addressed? :( |
It was fixed on the jest-styled-components side: |
Beauty! Thanks for the heads up on that :) |
Unfortunately, just tested in a branch of an active project. Still issues with the latest versions. |
I also tested it. Yep you are right. |
I have tested and found this is still an issue today with the following package versions:
As I understand it from looking over the code, jest-styled-components expects that each styled component class starts with "sc-", however, babel-plugin-styled-components seems to only prefix classes with "sc-" where the hash for that class starts with a number. This is because class names can't start with a number. I am using It sounds like the addition of the namespace option should have fixed this but I have tried setting the "namespace" to "sc-" as suggested in this issue jest-styled-components issue and while it is applied to some classes it isn't applied to all and so has fixed this in every instance. I believe that PR #276 correctly fixed this issue as it results in all styled component classes receiving the prefix. However, that PR was created some time ago and so is now out of date. |
This is still an issue on: "jest-styled-components": "7.0.8",
"styled-components": "5.3.1",
"babel-plugin-styled-components": "2.0.7",
"@babel/core": "7.17.9" And I cannot disable displayName for the babel plugin as we use it in testing |
for me the current workaround is to set |
Environment
System:
Binaries:
npmPackages:
Reproduction
https://repl.it/@robilarsamazon/jest-styled-components-5-and-babel-plugin-styled-components
Steps to reproduce
Click "Run" to run execute unit test
Expected Behavior
Test passes
Actual Behavior
Test fails
Notes
jest-styled-components
toHaveStyleRule()
depends on componentIds that start withsc-
. When babel-plugin-styled-components is enabled, componentIds are not prefixed.The text was updated successfully, but these errors were encountered: