-
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: support uppercase custom props in toHaveStyle #552
Changes from 3 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 |
---|---|---|
|
@@ -119,11 +119,11 @@ describe('.toHaveStyle', () => { | |
) | ||
}) | ||
|
||
test('handles inline custom properties', () => { | ||
test('handles inline custom properties (with uppercase letters)', () => { | ||
const {queryByTestId} = render(` | ||
<span data-testid="color-example" style="--color: blue">Hello World</span> | ||
<span data-testid="color-example" style="--accentColor: blue">Hello World</span> | ||
`) | ||
expect(queryByTestId('color-example')).toHaveStyle('--color: blue') | ||
expect(queryByTestId('color-example')).toHaveStyle('--accentColor: blue') | ||
}) | ||
|
||
test('handles global custom properties', () => { | ||
|
@@ -205,7 +205,7 @@ describe('.toHaveStyle', () => { | |
<span data-testid="color-example" style="font-size: 12px">Hello World</span> | ||
`) | ||
expect(queryByTestId('color-example')).toHaveStyle({ | ||
fontSize: 12 | ||
fontSize: 12, | ||
}) | ||
}) | ||
|
||
|
@@ -214,7 +214,7 @@ describe('.toHaveStyle', () => { | |
<span data-testid="color-example" style="font-size: 12rem">Hello World</span> | ||
`) | ||
expect(() => { | ||
expect(queryByTestId('color-example')).toHaveStyle({ fontSize: '12px' }) | ||
expect(queryByTestId('color-example')).toHaveStyle({fontSize: '12px'}) | ||
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. That one came from the husky pre-commit hook formatting the whole file. By the way running |
||
}).toThrowError() | ||
}) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ function isSubset(styles, computedStyle) { | |
Object.entries(styles).every( | ||
([prop, value]) => | ||
computedStyle[prop] === value || | ||
computedStyle.getPropertyValue(prop) === value || | ||
computedStyle.getPropertyValue(prop.toLowerCase()) === value, | ||
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.
After reading the whole discussion here, I thought this would be the least disruptive way. 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. I still think that we may need to detect specifically if the prop name corresponds to a custom CSS property. They are case-insensitive. The way the code is right now, if I have an element with Can't you do something along the lines of: const isCustomProp = prop.startsWith('--')
if (!isCustomProp) {
prop = prop.toLowerCase()
}
// Keep the condition as before 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. see my latest commit |
||
) | ||
) | ||
|
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.
same here