-
Notifications
You must be signed in to change notification settings - Fork 403
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 does not compare empty values #272
Comments
Yes, reproduced in CodeSandbox: https://codesandbox.io/s/react-testing-library-demo-3c133?file=/src/__tests__/hello.js it works fine if it was the only style property. When there are more, it gives false-positive. I also updated the original issue description |
I can confirm the bug. I don't know how to solve it yet, but: We underlie on the DOM API to parse the expected CSS object in a CSS before we compare it against the element's computed style, this API removes any invalid CSS attribute and it does not care about an "unset" attribute. So in your example, the matcher ends up comparing partially against the element.
|
I don't understand, why we need to serialize styles to string and then parse it back, losing the information about empty but defined keys. The color normalization is being done later in another function, why |
I don't know if I got your question, but we need to normalize the expected value to match it against the element's css. An element with the style
One function converts styled css in css text, another parses the css text in object like |
Yes, parsing CSS makes sense for the CSS-as-string argument. However, for the object format, it seems redundant, because keys order usually does not affect object equality. Is there a chance to refactor |
I got your point. I think it could work. Do you want to try it? |
Yes, I will give it a try and come back with a PR if this works out. |
The PR is out: #276 |
🎉 This issue has been resolved in version 5.11.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
@testing-library/jest-dom
version: 5.11.0node
version: 12.17.0npm
(oryarn
) version: 6.14.4Relevant code or config:
I expect that this assertion will fail, because
maxWidth
is not empty.It works, when I am using
toEqual
instead oftoHaveStyle
Suggested solution:
Somehow this information about empty values is lost around these lines:
jest-dom/src/to-have-style.js
Lines 60 to 61 in 7ea936d
A potential fix would be to check that all keys are from the expectation are defined on the element style definition.
The text was updated successfully, but these errors were encountered: