-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(devs-infra): add documentation for testing styles (#907)
- Loading branch information
Showing
7 changed files
with
55 additions
and
7 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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
id: testing-css-styles | ||
title: Testing CSS Styles | ||
--- | ||
|
||
Starting from **v9.0.0**, `jest-preset-angular` supports testing CSS styles. The supported style extensions following | ||
Angular support, which are: `css`, `sass`, `scss`, `less` and `styl`. This is provided default by `jest-preset-angular`. | ||
|
||
One now can use [window.getComputedStyle](https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle) | ||
to check styling of DOM elements. The styles which are returned by `window.getComputedStyle` come from styling files. | ||
|
||
## Example | ||
|
||
``` | ||
// ...TestBed setup | ||
const elementToFind = fixture.debugElement.nativeElement.querySelector('p'); | ||
expect(window.getComputedStyle(elementToFind).color).toEqual('red'); | ||
``` | ||
|
||
:::important | ||
|
||
To be able to use `window.getComputedStyle` API, please make sure that you remove | ||
|
||
``` | ||
Object.defineProperty(window, 'getComputedStyle', { | ||
value: () => { | ||
return { | ||
display: 'none', | ||
appearance: ['-webkit-appearance'], | ||
}; | ||
}, | ||
}); | ||
``` | ||
|
||
or any codes that override the default behavior of `window.getComputedStyle` in your setup file or your global mock file. | ||
|
||
::: |
4 changes: 2 additions & 2 deletions
4
website/docs/guides/babel-jest.md → website/docs/guides/using-with-babel.md
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
6 changes: 6 additions & 0 deletions
6
website/versioned_docs/version-8.x/guides/testing-css-styles.md
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
id: testing-css-styles | ||
title: Testing CSS Styles | ||
--- | ||
|
||
Testing CSS styles is only supported starting from **v9.0.0**. |
4 changes: 2 additions & 2 deletions
4
...ned_docs/version-8.x/guides/babel-jest.md → ...cs/version-8.x/guides/using-with-babel.md
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