-
Notifications
You must be signed in to change notification settings - Fork 379
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 assertion with invalid style (#564) #582
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,14 @@ function getStyleDeclaration(document, css) { | |
return styles | ||
} | ||
|
||
function isInvalidStyleDeclaration(name, value, computedStyle) { | ||
return ( | ||
name && | ||
!value && | ||
!computedStyle[name] && | ||
!computedStyle.getPropertyValue(name) | ||
) | ||
} | ||
Comment on lines
+17
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not fully evident (to me at least) why this works. I'm not saying I doubt that it works, I'm saying that perhaps this function could use a jsdoc to explain what it does. Or at the very least can you share here the logic? Perhaps no comment is needed, and I'm just having trouble to understand it myself. |
||
function isSubset(styles, computedStyle) { | ||
return ( | ||
!!Object.keys(styles).length && | ||
|
@@ -22,11 +30,16 @@ function isSubset(styles, computedStyle) { | |
const spellingVariants = [prop] | ||
if (!isCustomProperty) spellingVariants.push(prop.toLowerCase()) | ||
|
||
return spellingVariants.some( | ||
name => | ||
return spellingVariants.some(name => { | ||
if (isInvalidStyleDeclaration(name, value, computedStyle)) { | ||
return false | ||
} | ||
|
||
return ( | ||
computedStyle[name] === value || | ||
computedStyle.getPropertyValue(name) === value, | ||
) | ||
computedStyle.getPropertyValue(name) === 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.
nit: keep blank line between function declarations: