-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
9c3ea4e
commit 042db4d
Showing
3 changed files
with
136 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,98 @@ | ||
import {render} from './helpers/test-utils' | ||
|
||
test('.toHaveStyle', () => { | ||
const {container} = render(` | ||
describe('.toHaveStyle', () => { | ||
test('handles positive test cases', () => { | ||
const {container} = render(` | ||
<div class="label" style="background-color: blue; height: 100%"> | ||
Hello World | ||
</div> | ||
`) | ||
|
||
const style = document.createElement('style') | ||
style.innerHTML = ` | ||
.label { | ||
background-color: black; | ||
color: white; | ||
float: left; | ||
} | ||
` | ||
document.body.appendChild(style) | ||
document.body.appendChild(container) | ||
|
||
expect(container.querySelector('.label')).toHaveStyle(` | ||
height: 100%; | ||
color: white; | ||
background-color: blue; | ||
`) | ||
|
||
expect(container.querySelector('.label')).toHaveStyle(` | ||
background-color: blue; | ||
color: white; | ||
`) | ||
expect(container.querySelector('.label')).toHaveStyle( | ||
'background-color:blue;color:white', | ||
) | ||
|
||
expect(container.querySelector('.label')).not.toHaveStyle(` | ||
color: white; | ||
font-weight: bold; | ||
`) | ||
}) | ||
|
||
test('handles negative test cases', () => { | ||
const {container} = render(` | ||
<div class="label" style="background-color: blue; height: 100%"> | ||
Hello World | ||
</div> | ||
`) | ||
|
||
const style = document.createElement('style') | ||
style.innerHTML = ` | ||
const style = document.createElement('style') | ||
style.innerHTML = ` | ||
.label { | ||
background-color: black; | ||
color: white; | ||
float: left; | ||
} | ||
` | ||
document.body.appendChild(style) | ||
document.body.appendChild(container) | ||
document.body.appendChild(style) | ||
document.body.appendChild(container) | ||
|
||
expect(container.querySelector('.label')).toHaveStyle(` | ||
height: 100%; | ||
color: white; | ||
background-color: blue; | ||
`) | ||
expect(() => | ||
expect(container.querySelector('.label')).toHaveStyle( | ||
'font-weight: bold', | ||
), | ||
).toThrowError() | ||
expect(() => | ||
expect(container.querySelector('.label')).not.toHaveStyle('color: white'), | ||
).toThrowError() | ||
|
||
expect(container.querySelector('.label')).toHaveStyle(` | ||
background-color: blue; | ||
color: white; | ||
`) | ||
expect(container.querySelector('.label')).toHaveStyle( | ||
'background-color:blue;color:white', | ||
) | ||
// Make sure the test fails if the css syntax is not valid | ||
expect(() => | ||
expect(container.querySelector('.label')).not.toHaveStyle( | ||
'font-weight bold', | ||
), | ||
).toThrowError() | ||
expect(() => | ||
expect(container.querySelector('.label')).toHaveStyle('color white'), | ||
).toThrowError() | ||
|
||
expect(container.querySelector('.label')).not.toHaveStyle(` | ||
color: white; | ||
font-weight: bold; | ||
`) | ||
document.body.removeChild(style) | ||
document.body.removeChild(container) | ||
}) | ||
|
||
expect(() => | ||
expect(container.querySelector('.label')).toHaveStyle('font-weight: bold'), | ||
).toThrowError() | ||
expect(() => | ||
expect(container.querySelector('.label')).not.toHaveStyle('color: white'), | ||
).toThrowError() | ||
|
||
// Make sure the test fails if the css syntax is not valid | ||
expect(() => | ||
expect(container.querySelector('.label')).not.toHaveStyle( | ||
'font-weight bold', | ||
), | ||
).toThrowError() | ||
expect(() => | ||
expect(container.querySelector('.label')).toHaveStyle('color white'), | ||
).toThrowError() | ||
|
||
document.body.removeChild(style) | ||
document.body.removeChild(container) | ||
test('properly normalizes colors', () => { | ||
const {queryByTestId} = render(` | ||
<span data-testid="color-example" style="background-color: #123456">Hello World</span> | ||
`) | ||
expect(queryByTestId('color-example')).toHaveStyle( | ||
'background-color: #123456', | ||
) | ||
}) | ||
|
||
test('properly normalizes colors for border', () => { | ||
const {queryByTestId} = render(` | ||
<span data-testid="color-example" style="border: 1px solid #fff">Hello World</span> | ||
`) | ||
expect(queryByTestId('color-example')).toHaveStyle('border: 1px solid #fff') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters