@@ -48,8 +48,7 @@ <h2 id="getting-started" class="docs-header-link">
4848
4949< span class ="hljs-title function_ "> describe</ span > (< span class ="hljs-string "> 'my-component'</ span > , < span class ="hljs-function "> () =></ span > {
5050 < 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 > ]});
5352 fixture = < span class ="hljs-title class_ "> TestBed</ span > .< span class ="hljs-title function_ "> createComponent</ span > (< span class ="hljs-title class_ "> UserProfile</ span > );
5453 loader = < span class ="hljs-title class_ "> TestbedHarnessEnvironment</ span > .< span class ="hljs-title function_ "> loader</ span > (fixture);
5554 });
@@ -58,10 +57,10 @@ <h2 id="getting-started" class="docs-header-link">
5857< p > This code creates a fixture for < code > UserProfile</ code > and then creates a < code > HarnessLoader</ code > for that fixture.
5958The < code > HarnessLoader</ code > can then locate Angular Material components inside < code > UserProfile</ code > and create
6059harnesses for them. Note that < code > HarnessLoader</ code > and < code > TestbedHarnessEnvironment</ code > are loaded from
61- different paths. </ p >
60+ different paths.</ p >
6261< ul >
6362< 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 >
6564< li > < code > @angular/cdk/testing/testbed</ code > contains symbols that are used only in Karma tests.</ li >
6665< li > < code > @angular/cdk/testing/selenium-webdriver</ code > (not shown above) contains symbols that are used only in
6766Selenium WebDriver tests.</ li >
@@ -91,7 +90,7 @@ <h2 id="loading-an-angular-material-harness" class="docs-header-link">
9190with your tests.</ p >
9291< p > The example above retrieves all button harnesses and uses an array index to get the harness for a
9392specific 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 >
9594< p > You can load harnesses for a sub-section of the DOM within < code > UserProfile</ code > with the < code > getChildLoader</ code >
9695method on < code > HarnessLoader</ code > . For example, say that we know < code > UserProfile</ code > has a div,
9796< 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">
112111</ ul >
113112< p > In addition to these standard options, < code > MatButtonHarness</ code > also supports</ p >
114113< 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 >
116115</ ul >
117116< p > Using this method we could locate buttons as follows in our test:</ p >
118117< 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
156155 Comparison with and without component harnesses
157156 </ h2 >
158157 < 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
160159test to verify that when the user chooses an issue type the proper report displays. First consider
161160what the test might look like without using component harnesses:</ p >
162161< 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 > {
163162 < 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 > >;
164163
165164 < 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 > ({
167166 < span class ="hljs-attr "> imports</ span > : [< span class ="hljs-title class_ "> IssueReportSelectorModule</ span > ],
168167 < span class ="hljs-attr "> declarations</ span > : [< span class ="hljs-title class_ "> IssueReportSelector</ span > ],
169- }). < span class =" hljs-title function_ " > compileComponents </ span > () ;
168+ });
170169
171170 fixture = < span class ="hljs-title class_ "> TestBed</ span > .< span class ="hljs-title function_ "> createComponent</ span > (< span class ="hljs-title class_ "> IssueReportSelector</ span > );
172171 fixture.< span class ="hljs-title function_ "> detectChanges</ span > ();
@@ -192,10 +191,10 @@ <h2 id="comparison-with-and-without-component-harnesses" class="docs-header-link
192191 < span class ="hljs-keyword "> let</ span > < span class ="hljs-attr "> loader</ span > : < span class ="hljs-title class_ "> HarnessLoader</ span > ;
193192
194193 < 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 > ({
196195 < span class ="hljs-attr "> imports</ span > : [< span class ="hljs-title class_ "> IssueReportSelectorModule</ span > ],
197196 < span class ="hljs-attr "> declarations</ span > : [< span class ="hljs-title class_ "> IssueReportSelector</ span > ],
198- }). < span class =" hljs-title function_ " > compileComponents </ span > () ;
197+ });
199198
200199 fixture = < span class ="hljs-title class_ "> TestBed</ span > .< span class ="hljs-title function_ "> createComponent</ span > (< span class ="hljs-title class_ "> IssueReportSelector</ span > );
201200 fixture.< span class ="hljs-title function_ "> detectChanges</ span > ();
@@ -236,12 +235,12 @@ <h3 id="tests-that-are-more-robust" class="docs-header-link">
236235< code > <mat-select></ code > , such as < code > .mat-select-trigger</ code > . If the internal DOM of < code > <mat-select></ code > changes, these
237236queries may stop working. While the Angular team tries to minimize this type of change, some
238237features 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 >
240239< p > In addition to DOM structure, component asynchronicity often offers a challenge when updating
241240components. If a component changes between synchronous and asynchronous, downstream unit tests may
242241break due to expectations around timing. Tests then require the addition or removal of some
243242arcane 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
245244with all asynchronous APIs. When a test uses these harnesses, changes to asynchronicity become
246245far more manageable.</ p >
247246< p > Both DOM structure and asynchronicity are < em > implementation details</ em > of Angular Material's components.
0 commit comments