diff --git a/src/__tests__/to-have-style.js b/src/__tests__/to-have-style.js
index 6a636f95..0d94efaa 100644
--- a/src/__tests__/to-have-style.js
+++ b/src/__tests__/to-have-style.js
@@ -103,6 +103,9 @@ describe('.toHaveStyle', () => {
expect(container.querySelector('.label')).toHaveStyle('color white'),
).toThrowError()
+ expect(() =>
+ expect(container.querySelector('.label')).toHaveStyle('--color: black'),
+ ).toThrowError()
document.body.removeChild(style)
document.body.removeChild(container)
})
@@ -116,6 +119,33 @@ describe('.toHaveStyle', () => {
)
})
+ test('handles inline custom properties', () => {
+ const {queryByTestId} = render(`
+ Hello World
+ `)
+ expect(queryByTestId('color-example')).toHaveStyle('--color: blue')
+ })
+
+ test('handles global custom properties', () => {
+ const style = document.createElement('style')
+ style.innerHTML = `
+ div {
+ --color: blue;
+ }
+ `
+
+ const {container} = render(`
+
+ Hello world
+
+ `)
+
+ document.body.appendChild(style)
+ document.body.appendChild(container)
+
+ expect(container).toHaveStyle(`--color: blue`)
+ })
+
test('properly normalizes colors for border', () => {
const {queryByTestId} = render(`
Hello World
@@ -170,6 +200,24 @@ describe('.toHaveStyle', () => {
})
})
+ test('Uses px as the default unit', () => {
+ const {queryByTestId} = render(`
+ Hello World
+ `)
+ expect(queryByTestId('color-example')).toHaveStyle({
+ fontSize: 12
+ })
+ })
+
+ test('Fails with an invalid unit', () => {
+ const {queryByTestId} = render(`
+ Hello World
+ `)
+ expect(() => {
+ expect(queryByTestId('color-example')).toHaveStyle({ fontSize: '12px' })
+ }).toThrowError()
+ })
+
test('supports dash-cased property names', () => {
const {container} = render(`
diff --git a/src/to-have-style.js b/src/to-have-style.js
index a404c40a..7926827b 100644
--- a/src/to-have-style.js
+++ b/src/to-have-style.js
@@ -22,7 +22,7 @@ function isSubset(styles, computedStyle) {
Object.entries(styles).every(
([prop, value]) =>
computedStyle[prop] === value ||
- computedStyle[prop.toLowerCase()] === value,
+ computedStyle.getPropertyValue(prop.toLowerCase()) === value,
)
)
}