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
feat(material/testing): Modify HarnessLoader with the addition of
`getHarnessAtIndex` and `countHarnesses`
These two new functions are intended to expand harness testing
functionality by providing built-in functions for commonly used
patterns.
* `getHarnessAtIndex` functions similarly to `getHarness`, but returns
a harness for the matching component instance with the given index.
An example use case is to fetch the nth MatOptionHarness on screen.
* `countHarnesses` simply counts the number of matching component
instances and returns the result.
Documentation is updated to reflect this changes, and adds a missing row
for the `hasHarness` function
Manually tested using the MatInputHarness tests
Copy file name to clipboardExpand all lines: src/cdk/testing/test-harnesses.md
+4-1
Original file line number
Diff line number
Diff line change
@@ -134,9 +134,12 @@ are used to create `ComponentHarness` instances for elements under this root ele
134
134
|`getChildLoader(selector: string): Promise<HarnessLoader>`| Searches for an element matching the given selector below the root element of this `HarnessLoader`, and returns a new `HarnessLoader` rooted at the first matching element |
135
135
|`getAllChildLoaders(selector: string): Promise<HarnessLoader[]>`| Acts like `getChildLoader`, but returns an array of `HarnessLoader` instances, one for each matching element, rather than just the first matching element |
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
+
|`getHarnessAtIndex<T extends ComponentHarness>(harnessType: ComponentHarnessConstructor<T> \| HarnessPredicate<T>, index: number): Promise<T>`| Acts like `getHarness`, but returns an instance of the harness corresponding to the matching element with the given index (zero-indexed) |
137
138
|`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 |
139
+
|`countHarnesses<T extends ComponentHarness>(harnessType: ComponentHarnessConstructor<T> \| HarnessPredicate<T>): Promise<number>`| Counts the number of instances of the given `ComponentHarness` class or `HarnessPredicate` below the root element of this `HarnessLoader`, and returns the result. |
140
+
|`hasHarness<T extends ComponentHarness>(harnessType: ComponentHarnessConstructor<T> \| HarnessPredicate<T>): Promise<boolean>`| Returns true if an instance of the given `ComponentHarness` class or `HarnessPredicate` exists below the root element of this `HarnessLoader`|
138
141
139
-
Calls to `getHarness` and `getAllHarnesses` can either take `ComponentHarness` subclass or a
142
+
Calls to the harness functions can either take `ComponentHarness` subclass or a
140
143
`HarnessPredicate`. `HarnessPredicate` applies additional restrictions to the search (e.g. searching
141
144
for a button that has some particular text, etc). The
142
145
[details of `HarnessPredicate`](#filtering-harness-instances-with-harnesspredicate) are discussed in
0 commit comments