You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(testing): add methods for accessing projected content in component container harnesses (#20556)
Switches over all the harnesses for components that can contain projected user content to extend `ContentContainerComponentHarness` which will allow consumers to query for harnesses inside the element.
I've also deprecated a few similar methods that were added before `ContentContainerComponentHarness` was available. That being said, I wasn't totally sure whether the testing APIs fall under the same deprecation policy as everything else so I played it safe.
Finally, I cleaned up some `@dynamic` annotations which weren't doing anything, as far as I could tell.
Co-authored-by: Wagner Maciel <wagnermaciel@google.com>
In most cases, you can create a `HarnessLoader` in the `beforeEach` block using
68
68
`TestbedHarnessEnvironment.loader(fixture)` and then use that `HarnessLoader` to create any
69
69
necessary `ComponentHarness` instances. The other methods cover special cases as shown in this
70
-
example:
70
+
example:
71
71
72
72
Consider a reusable dialog-button component that opens a dialog on click, containing the following
73
73
components, each with a corresponding harness:
@@ -136,7 +136,7 @@ are used to create `ComponentHarness` instances for elements under this root ele
136
136
|`getHarness<T extends ComponentHarness>(harnessType: ComponentHarnessConstructor<T> \| HarnessPredicate<T>): Promise<T>`| Searches for an instance of the given `ComponentHarness` class or `HarnessPredicate` below the root element of this `HarnessLoader` and returns an instance of the harness corresponding to the first matching element |
137
137
|`getAllHarnesses<T extends ComponentHarness>(harnessType: ComponentHarnessConstructor<T> \| HarnessPredicate<T>): Promise<T[]>`| Acts like `getHarness`, but returns an array of harness instances, one for each matching element, rather than just the first matching element |
138
138
139
-
Calls to `getHarness` and `getAllHarnesses` can either take `ComponentHarness` subclass or a
139
+
Calls to `getHarness` and `getAllHarnesses` can either take `ComponentHarness` subclass or a
140
140
`HarnessPredicate`. `HarnessPredicate` applies additional restrictions to the search (e.g. searching
141
141
for a button that has some particular text, etc). The
142
142
[details of `HarnessPredicate`](#filtering-harness-instances-with-harnesspredicate) are discussed in
@@ -149,7 +149,7 @@ created manually.
149
149
150
150
To support both unit and end-to-end tests, and to insulate tests against changes in
151
151
asynchronous behavior, almost all harness methods are asynchronous and return a `Promise`;
@@ -226,7 +226,7 @@ corresponding component. You can access the component's host element via the `ho
226
226
the `ComponentHarness` base class.
227
227
228
228
`ComponentHarness` additionally offers several methods for locating elements within the component's
229
-
DOM. These methods are `locatorFor`, `locatorForOptional`, and `locatorForAll`.
229
+
DOM. These methods are `locatorFor`, `locatorForOptional`, and `locatorForAll`.
230
230
Note, though, that these methods do not directly find elements. Instead, they _create functions_
231
231
that find elements. This approach safeguards against caching references to out-of-date elements. For
232
232
example, when an `ngIf` hides and then shows an element, the result is a new DOM element; using
@@ -395,7 +395,7 @@ for adding options.
395
395
|`add(description: string, predicate: (harness: T) => Promise<boolean>): HarnessPredicate<T>`| Creates a new `HarnessPredicate` that enforces all of the conditions of the current one, plus the new constraint specified by the `predicate` parameter. |
396
396
397
397
For example, when working with a menu it would likely be useful to add a way to filter based on
398
-
trigger text and to filter menu items based on their text:
398
+
trigger text and to filter menu items based on their text:
@@ -482,17 +482,14 @@ several APIs that can be used to create `HarnessLoader` instances for cases like
482
482
|`harnessLoaderForOptional(selector: string): Promise<HarnessLoader \| null>`| Gets a `Promise` for a `HarnessLoader` rooted at the first element matching the given selector, if no element is found the `Promise` resolves to `null`. |
483
483
|`harnessLoaderForAll(selector: string): Promise<HarnessLoader[]>`| Gets a `Promise` for a list of `HarnessLoader`, one rooted at each element matching the given selector. |
484
484
485
+
485
486
The `MyPopup` component discussed earlier is a good example of a component with arbitrary content
486
-
that users may want to load harnesses for. `MyPopupHarness` could add support for this:
487
+
that users may want to load harnesses for. `MyPopupHarness` could add support for this by
0 commit comments