Skip to content

Commit 45db7cc

Browse files
committed
main - 4df402e build: enforce compileComponents isn't called
1 parent a33687c commit 45db7cc

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

docs-content/guides/using-component-harnesses.md.html

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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">&#x27;my-component&#x27;</span>, <span class="hljs-function">() =&gt;</span> {
5050
<span class="hljs-title function_">beforeEach</span>(<span class="hljs-title function_">async</span> () =&gt; {
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.
5958
The <code>HarnessLoader</code> can then locate Angular Material components inside <code>UserProfile</code> and create
6059
harnesses 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
6766
Selenium WebDriver tests.</li>
@@ -91,7 +90,7 @@ <h2 id="loading-an-angular-material-harness" class="docs-header-link">
9190
with your tests.</p>
9291
<p>The example above retrieves all button harnesses and uses an array index to get the harness for a
9392
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>
9594
<p>You can load harnesses for a sub-section of the DOM within <code>UserProfile</code> with the <code>getChildLoader</code>
9695
method on <code>HarnessLoader</code>. For example, say that we know <code>UserProfile</code> has a div,
9796
<code>&lt;div class=&quot;footer&quot;&gt;</code>, and we want the button inside that specific <code>&lt;div&gt;</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">&#x27;should work&#x27;</span>, <span class="hljs-title function_">async</span> () =&gt; {
@@ -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>&lt;issue-report-selector&gt;</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
160159
test to verify that when the user chooses an issue type the proper report displays. First consider
161160
what 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">&#x27;issue-report-selector&#x27;</span>, <span class="hljs-function">() =&gt;</span> {
163162
<span class="hljs-keyword">let</span> <span class="hljs-attr">fixture</span>: <span class="hljs-title class_">ComponentFixture</span>&lt;<span class="hljs-title class_">IssueReportSelector</span>&gt;;
164163

165164
<span class="hljs-title function_">beforeEach</span>(<span class="hljs-title function_">async</span> () =&gt; {
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> () =&gt; {
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>&lt;mat-select&gt;</code>, such as <code>.mat-select-trigger</code>. If the internal DOM of <code>&lt;mat-select&gt;</code> changes, these
237236
queries may stop working. While the Angular team tries to minimize this type of change, some
238237
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>
240239
<p>In addition to DOM structure, component asynchronicity often offers a challenge when updating
241240
components. If a component changes between synchronous and asynchronous, downstream unit tests may
242241
break due to expectations around timing. Tests then require the addition or removal of some
243242
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
245244
with all asynchronous APIs. When a test uses these harnesses, changes to asynchronicity become
246245
far more manageable.</p>
247246
<p>Both DOM structure and asynchronicity are <em>implementation details</em> of Angular Material&#39;s components.

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@angular/components-examples",
3-
"version": "20.1.0-next.1+sha-b9299cb",
3+
"version": "20.1.0-next.1+sha-4df402e",
44
"description": "Angular Components Examples",
55
"private": true,
66
"repository": {
@@ -259,15 +259,15 @@
259259
},
260260
"homepage": "https://github.com/angular/components#readme",
261261
"peerDependencies": {
262-
"@angular/cdk": "20.1.0-next.1+sha-b9299cb",
263-
"@angular/cdk-experimental": "20.1.0-next.1+sha-b9299cb",
262+
"@angular/cdk": "20.1.0-next.1+sha-4df402e",
263+
"@angular/cdk-experimental": "20.1.0-next.1+sha-4df402e",
264264
"@angular/core": "^20.0.0-0 || ^20.1.0-0 || ^20.2.0-0 || ^20.3.0-0 || ^21.0.0-0",
265265
"@angular/common": "^20.0.0-0 || ^20.1.0-0 || ^20.2.0-0 || ^20.3.0-0 || ^21.0.0-0",
266-
"@angular/material": "20.1.0-next.1+sha-b9299cb",
267-
"@angular/material-experimental": "20.1.0-next.1+sha-b9299cb",
268-
"@angular/material-moment-adapter": "20.1.0-next.1+sha-b9299cb",
269-
"@angular/material-luxon-adapter": "20.1.0-next.1+sha-b9299cb",
270-
"@angular/material-date-fns-adapter": "20.1.0-next.1+sha-b9299cb"
266+
"@angular/material": "20.1.0-next.1+sha-4df402e",
267+
"@angular/material-experimental": "20.1.0-next.1+sha-4df402e",
268+
"@angular/material-moment-adapter": "20.1.0-next.1+sha-4df402e",
269+
"@angular/material-luxon-adapter": "20.1.0-next.1+sha-4df402e",
270+
"@angular/material-date-fns-adapter": "20.1.0-next.1+sha-4df402e"
271271
},
272272
"devDependencies": {
273273
"@angular/cdk": "workspace:*",

0 commit comments

Comments
 (0)