@@ -48,8 +48,7 @@ <h2 id="getting-started" class="docs-header-link">
48
48
49
49
< span class ="hljs-title function_ "> describe</ span > (< span class ="hljs-string "> 'my-component'</ span > , < span class ="hljs-function "> () =></ span > {
50
50
< span class ="hljs-title function_ "> beforeEach</ span > (< span class ="hljs-title function_ "> async</ span > () => {
51
- < span class ="hljs-keyword "> await</ span > < span class ="hljs-title class_ "> TestBed</ span > .< span class ="hljs-title function_ "> configureTestingModule</ span > ({< span class ="hljs-attr "> imports</ span > : [< span class ="hljs-title class_ "> MyModule</ span > ], < span class ="hljs-attr "> declarations</ span > : [< span class ="hljs-title class_ "> UserProfile</ span > ]})
52
- .< span class ="hljs-title function_ "> compileComponents</ span > ();
51
+ < span class ="hljs-title class_ "> TestBed</ span > .< span class ="hljs-title function_ "> configureTestingModule</ span > ({< span class ="hljs-attr "> imports</ span > : [< span class ="hljs-title class_ "> MyModule</ span > ], < span class ="hljs-attr "> declarations</ span > : [< span class ="hljs-title class_ "> UserProfile</ span > ]});
53
52
fixture = < span class ="hljs-title class_ "> TestBed</ span > .< span class ="hljs-title function_ "> createComponent</ span > (< span class ="hljs-title class_ "> UserProfile</ span > );
54
53
loader = < span class ="hljs-title class_ "> TestbedHarnessEnvironment</ span > .< span class ="hljs-title function_ "> loader</ span > (fixture);
55
54
});
@@ -58,10 +57,10 @@ <h2 id="getting-started" class="docs-header-link">
58
57
< p > This code creates a fixture for < code > UserProfile</ code > and then creates a < code > HarnessLoader</ code > for that fixture.
59
58
The < code > HarnessLoader</ code > can then locate Angular Material components inside < code > UserProfile</ code > and create
60
59
harnesses for them. Note that < code > HarnessLoader</ code > and < code > TestbedHarnessEnvironment</ code > are loaded from
61
- different paths. </ p >
60
+ different paths.</ p >
62
61
< ul >
63
62
< li > < code > @angular/cdk/testing</ code > contains symbols that are shared regardless of the environment your tests
64
- are in. </ li >
63
+ are in.</ li >
65
64
< li > < code > @angular/cdk/testing/testbed</ code > contains symbols that are used only in Karma tests.</ li >
66
65
< li > < code > @angular/cdk/testing/selenium-webdriver</ code > (not shown above) contains symbols that are used only in
67
66
Selenium WebDriver tests.</ li >
@@ -91,7 +90,7 @@ <h2 id="loading-an-angular-material-harness" class="docs-header-link">
91
90
with your tests.</ p >
92
91
< p > The example above retrieves all button harnesses and uses an array index to get the harness for a
93
92
specific button. However, if the number or order of buttons changes, this test will break. You can
94
- write a less brittle test by instead asking for only a subset of harnesses inside < code > UserProfile</ code > . </ p >
93
+ write a less brittle test by instead asking for only a subset of harnesses inside < code > UserProfile</ code > .</ p >
95
94
< p > You can load harnesses for a sub-section of the DOM within < code > UserProfile</ code > with the < code > getChildLoader</ code >
96
95
method on < code > HarnessLoader</ code > . For example, say that we know < code > UserProfile</ code > has a div,
97
96
< code > <div class="footer"></ code > , and we want the button inside that specific < code > <div></ code > . We can accomplish this
@@ -112,7 +111,7 @@ <h2 id="loading-an-angular-material-harness" class="docs-header-link">
112
111
</ ul >
113
112
< p > In addition to these standard options, < code > MatButtonHarness</ code > also supports</ p >
114
113
< ul >
115
- < li > < code > text</ code > - String text or regular expressions that matches the text content of the button </ li >
114
+ < li > < code > text</ code > - String text or regular expressions that matches the text content of the button</ li >
116
115
</ ul >
117
116
< p > Using this method we could locate buttons as follows in our test:</ p >
118
117
< pre > < code class ="language-ts "> < span class ="hljs-title function_ "> it</ span > (< span class ="hljs-string "> 'should work'</ span > , < span class ="hljs-title function_ "> async</ span > () => {
@@ -156,17 +155,17 @@ <h2 id="comparison-with-and-without-component-harnesses" class="docs-header-link
156
155
Comparison with and without component harnesses
157
156
</ h2 >
158
157
< p > Consider an < code > <issue-report-selector></ code > component that you want to test. It allows a user to
159
- choose an issue type and display the necessary form create report for that issue type. You need a
158
+ choose an issue type and display the necessary form create report for that issue type. You need a
160
159
test to verify that when the user chooses an issue type the proper report displays. First consider
161
160
what the test might look like without using component harnesses:</ p >
162
161
< pre > < code class ="language-ts "> < span class ="hljs-title function_ "> describe</ span > (< span class ="hljs-string "> 'issue-report-selector'</ span > , < span class ="hljs-function "> () =></ span > {
163
162
< span class ="hljs-keyword "> let</ span > < span class ="hljs-attr "> fixture</ span > : < span class ="hljs-title class_ "> ComponentFixture</ span > << span class ="hljs-title class_ "> IssueReportSelector</ span > >;
164
163
165
164
< span class ="hljs-title function_ "> beforeEach</ span > (< span class ="hljs-title function_ "> async</ span > () => {
166
- < span class ="hljs-keyword " > await </ span > < span class =" hljs- title class_ "> TestBed</ span > .< span class ="hljs-title function_ "> configureTestingModule</ span > ({
165
+ < span class ="hljs-title class_ "> TestBed</ span > .< span class ="hljs-title function_ "> configureTestingModule</ span > ({
167
166
< span class ="hljs-attr "> imports</ span > : [< span class ="hljs-title class_ "> IssueReportSelectorModule</ span > ],
168
167
< span class ="hljs-attr "> declarations</ span > : [< span class ="hljs-title class_ "> IssueReportSelector</ span > ],
169
- }). < span class =" hljs-title function_ " > compileComponents </ span > () ;
168
+ });
170
169
171
170
fixture = < span class ="hljs-title class_ "> TestBed</ span > .< span class ="hljs-title function_ "> createComponent</ span > (< span class ="hljs-title class_ "> IssueReportSelector</ span > );
172
171
fixture.< span class ="hljs-title function_ "> detectChanges</ span > ();
@@ -192,10 +191,10 @@ <h2 id="comparison-with-and-without-component-harnesses" class="docs-header-link
192
191
< span class ="hljs-keyword "> let</ span > < span class ="hljs-attr "> loader</ span > : < span class ="hljs-title class_ "> HarnessLoader</ span > ;
193
192
194
193
< span class ="hljs-title function_ "> beforeEach</ span > (< span class ="hljs-title function_ "> async</ span > () => {
195
- < span class ="hljs-keyword " > await </ span > < span class =" hljs- title class_ "> TestBed</ span > .< span class ="hljs-title function_ "> configureTestingModule</ span > ({
194
+ < span class ="hljs-title class_ "> TestBed</ span > .< span class ="hljs-title function_ "> configureTestingModule</ span > ({
196
195
< span class ="hljs-attr "> imports</ span > : [< span class ="hljs-title class_ "> IssueReportSelectorModule</ span > ],
197
196
< span class ="hljs-attr "> declarations</ span > : [< span class ="hljs-title class_ "> IssueReportSelector</ span > ],
198
- }). < span class =" hljs-title function_ " > compileComponents </ span > () ;
197
+ });
199
198
200
199
fixture = < span class ="hljs-title class_ "> TestBed</ span > .< span class ="hljs-title function_ "> createComponent</ span > (< span class ="hljs-title class_ "> IssueReportSelector</ span > );
201
200
fixture.< span class ="hljs-title function_ "> detectChanges</ span > ();
@@ -236,12 +235,12 @@ <h3 id="tests-that-are-more-robust" class="docs-header-link">
236
235
< code > <mat-select></ code > , such as < code > .mat-select-trigger</ code > . If the internal DOM of < code > <mat-select></ code > changes, these
237
236
queries may stop working. While the Angular team tries to minimize this type of change, some
238
237
features and bug fixes ultimately require restructuring the DOM. By using the Angular Material
239
- harnesses, you avoid depending on internal DOM structure directly. </ p >
238
+ harnesses, you avoid depending on internal DOM structure directly.</ p >
240
239
< p > In addition to DOM structure, component asynchronicity often offers a challenge when updating
241
240
components. If a component changes between synchronous and asynchronous, downstream unit tests may
242
241
break due to expectations around timing. Tests then require the addition or removal of some
243
242
arcane combination of < code > whenStable</ code > , < code > flushMicroTasks</ code > , < code > tick</ code > , or < code > detectChanges</ code > . Component
244
- harnesses, however, avoid this problem by normalizing the asynchronicity of all component behaviors
243
+ harnesses, however, avoid this problem by normalizing the asynchronicity of all component behaviors
245
244
with all asynchronous APIs. When a test uses these harnesses, changes to asynchronicity become
246
245
far more manageable.</ p >
247
246
< p > Both DOM structure and asynchronicity are < em > implementation details</ em > of Angular Material's components.
0 commit comments