-
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
fix(toHaveStyle): strictly match empty values #276
Conversation
Codecov Report
@@ Coverage Diff @@
## master #276 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 23 23
Lines 320 315 -5
Branches 71 72 +1
=========================================
- Hits 320 315 -5
Continue to review full report at Codecov.
|
function parseJStoCSS(document, css) { | ||
const sandboxElement = document.createElement('div') | ||
Object.assign(sandboxElement.style, css) | ||
return sandboxElement.style.cssText | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is currently not used anywhere else, so I decided to drop this completely
@@ -37,7 +38,7 @@ function printoutStyles(styles) { | |||
// received computed styles | |||
function expectedDiff(expected, computedStyles) { | |||
const received = Array.from(computedStyles) | |||
.filter(prop => expected[prop]) | |||
.filter(prop => expected[prop] !== undefined) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed to get a proper diff for expect(something).toHaveStyle({width: ''})
(expect width to be empty). Without this change it prints "the diff has no visual difference"
@@ -21,7 +21,8 @@ function isSubset(styles, computedStyle) { | |||
!!Object.keys(styles).length && | |||
Object.entries(styles).every( | |||
([prop, value]) => | |||
computedStyle.getPropertyValue(prop.toLowerCase()) === value, | |||
computedStyle[prop] === value || | |||
computedStyle[prop.toLowerCase()] === value, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
computedStyle.getPropertyValue
supports only dash-cased notation. Property getters work for both dash and camelCase
🎉 This PR is included in version 5.11.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
@all-contributors please add @just-boris for bug, code, test |
I've put up a pull request to add @just-boris! 🎉 |
What:
fixes the issue #272
Why:
Current implementation allows false positive matches. More examples in the linked issue
Checklist: