Open
Description
@testing-library/jest-dom
version: 5.1.1node
version: 12.16.2npm
(oryarn
) version: 1.22.4
Relevant code or config:
test.only('failing test', () => {
const style = document.createElement('style')
style.innerHTML = `
div {
--color: blue;
}
`
const {container} = render(`
<div>
Hello world
</div>
`)
document.body.appendChild(style)
document.body.appendChild(container)
expect(container).toHaveStyle(`--color: blue`)
})
Problem description:
If you were to run the test above, this would fail because toHaveStyle
doesn't take account of CSS custom properties.
Suggested solution:
I think the PR #276 caused this behavior. Indeed, the isSubset
function has been changed and doesn't use getPropertyValue
anymore (see this line).
It seems a custom property on CSSStyleDeclaration
can't be accessed simply using the property key (for example computedStyle['--color']
), you explicitely have to use getPropertyValue
.
I forked the repo and changed back the isSubset
function to use getPropertyValue
and things work well. That may be a solution (I assume there's a reason why it's been changed so things may not be so simple).