Skip to content

Commit 1483058

Browse files
committed
fix: keep toHaveStyle up-to-date w/ jest-dom's
1 parent 2df860e commit 1483058

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/toHaveStyle.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,23 @@ function parseJStoCSS(document, styles) {
3030

3131
function getStyleDeclaration(document, css) {
3232
const styles = {};
33+
34+
// The next block is necessary to normalize colors
3335
const copy = document.createElement('div');
34-
Object.keys(css).forEach(property => {
35-
copy.style[property] = css[property];
36-
styles[property] = copy.style[property];
36+
Object.keys(css).forEach(prop => {
37+
copy.style[prop] = css[prop];
38+
styles[prop] = copy.style[prop];
3739
});
40+
3841
return styles;
3942
}
4043

4144
function styleIsSubset(styles, computedStyle) {
4245
return (
4346
!!Object.keys(styles).length &&
44-
Object.entries(styles).every(([prop, value]) => computedStyle.getPropertyValue(prop.toLowerCase()) === value)
47+
Object.entries(styles).every(
48+
([prop, value]) => computedStyle[prop] === value || computedStyle.getPropertyValue(prop.toLowerCase()) === value
49+
)
4550
);
4651
}
4752

@@ -58,7 +63,7 @@ function printoutStyles(styles) {
5863

5964
function expectedStyleDiff(expected, computedStyles) {
6065
const received = Array.from(computedStyles)
61-
.filter(prop => expected[prop])
66+
.filter(prop => expected[prop] !== undefined)
6267
.reduce(
6368
(obj, prop) =>
6469
Object.assign(obj, {

0 commit comments

Comments
 (0)