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
toHaveStyle inconsistency with colors #49
Comments
toHaveStyle(`
background-color: #fff;
`) ...will fail, because toHaveStyle(`
border: 1px solid #fff;
`) ... is fine, because Yes, it is annoying. Would love to have consistent format. |
Kk, I do believe it is ready! I am going to add the test case (border) above just to verify then will merge it in! |
@gnapse The PR has been merged as a |
🎉 This issue has been resolved in version 1.12.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This still happens in:
|
Can you expand a bit on the full example? In the screenshot we don't see the code being tested, how it sets this color that it is then not found. Or better yet, a minimal reproducible example/repo. |
Here's a minimal example, where hex is still converted to rgb: https://codesandbox.io/s/heuristic-ritchie-5hgn8 |
Oh it passes for me now as well, maybe it was just the text not matching 🤦♂️. I realised that my actual issue was that I was trying to use |
@gnapse I run some tests with CodeSandbox and it gives me the same error when i use styled-components, but it works fine when i put inline style as you did. https://codesandbox.io/s/rtl-tohavestyle-error-fq669f?file=/src/App.js |
I'm hitting this too with a different css-in-js library that uses a similar class-name injection approach as styled-components. It's strange though, because some tests that involve colors still pass, while others fail because of the automatic conversion from color names to rgb colors. I'm hitting this after upgrading from 5 to 6. It's obviously a tricky edge case so I'll continue to investigate and post back if I have any more information to go off of. |
jest-dom
version: 1.11.0node
version: 8.11.3react-testing-library
version: 4.1.4Relevant code or config:
What you did:
I rendered an element with a specific hex background color in its
style
s.What happened:
I can't assert back that the
background-color
style is indeed there. This is because the actual styles I get back from the element give me the color in thergb(r, g, b)
format:Problem description:
The problem is that users are forced to use the
rgb()
format.Suggested solution:
It'd be nice if
toHaveStyle
would convert hex colors to thergb(r, g, b)
format so this is transparent for users. Otherwise document the caveat and maybe provide the user with some alternative or direct them to a library they can use to make this conversion, and that they make sure they always usergb(r, g, b)
either directly or by converting their hex value dynamically themselves.The text was updated successfully, but these errors were encountered: