-
Notifications
You must be signed in to change notification settings - Fork 412
Changed toHaveStyle to use getPropertyValue instead of accessing the property directly #285
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
Changes from 1 commit
5c24818
3966819
48ae84d
1c584c1
f2cb1e9
c13abf5
d5afec4
e54eff9
0d869d8
e2b48ac
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 |
---|---|---|
|
@@ -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 customer properties', () => { | ||
const {queryByTestId} = render(` | ||
<span data-testid="color-example" style="--color: blue">Hello World</span> | ||
`) | ||
luanraithz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(queryByTestId('color-example')).toHaveStyle('--color: blue') | ||
}) | ||
|
||
test('handles global customer properties', () => { | ||
luanraithz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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`) | ||
}) | ||
|
||
test('properly normalizes colors for border', () => { | ||
const {queryByTestId} = render(` | ||
<span data-testid="color-example" style="border: 1px solid #fff">Hello World</span> | ||
|
@@ -170,6 +200,24 @@ describe('.toHaveStyle', () => { | |
}) | ||
}) | ||
|
||
test("doesn't consider the unit if it isn't explicitly set ", () => { | ||
const {queryByTestId} = render(` | ||
<span data-testid="color-example" style="font-size: 12rem">Hello World</span> | ||
`) | ||
expect(queryByTestId('color-example')).toHaveStyle({ | ||
fontSize: 12 | ||
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. Why would this match Also: This test only works in JSDOM. In an actual browser the value would be resolved to (depending on the base font size) to 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. You are right! This test case doesn't make any sense as it is going to work only in JSDOM. Btw, I didn't know that, thanks! I'm going to change that. It isn't clear to me if you are only against this test case or the idea of the api. 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. Just want to make sure that we're not documenting a test case that wouldn't work in a correct DOM environment. 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. Follow up on this. It seems from the discussion above that there's still something to be addressed here before this is ready. Right? 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. Is JSDOM actually returning 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 changed to |
||
}) | ||
}) | ||
|
||
test("Fails with an invalid unit", () => { | ||
gnapse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const {queryByTestId} = render(` | ||
<span data-testid="color-example" style="font-size: 12rem">Hello World</span> | ||
`) | ||
luanraithz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(() => { | ||
expect(queryByTestId('color-example')).toHaveStyle({ fontSize: '12px' }) | ||
}).toThrowError() | ||
}) | ||
|
||
test('supports dash-cased property names', () => { | ||
const {container} = render(` | ||
<div class="label" style="background-color: blue; height: 100%"> | ||
|
Uh oh!
There was an error while loading. Please reload this page.