@@ -96,13 +96,31 @@ export interface HarnessLoader {
96
96
*/
97
97
getHarness < T extends ComponentHarness > ( query : HarnessQuery < T > ) : Promise < T > ;
98
98
99
+ /**
100
+ * Searches for an instance of the component corresponding to the given harness type under the
101
+ * `HarnessLoader`'s root element, and returns a `ComponentHarness` for that instance. If multiple
102
+ * matching components are found, a harness for the first one is returned. If no matching
103
+ * component is found, null is returned.
104
+ * @param query A query for a harness to create
105
+ * @return An instance of the given harness type (or null if not found).
106
+ */
107
+ getOptionalHarness < T extends ComponentHarness > ( query : HarnessQuery < T > ) : Promise < T | null > ;
108
+
99
109
/**
100
110
* Searches for all instances of the component corresponding to the given harness type under the
101
111
* `HarnessLoader`'s root element, and returns a list `ComponentHarness` for each instance.
102
112
* @param query A query for a harness to create
103
113
* @return A list instances of the given harness type.
104
114
*/
105
115
getAllHarnesses < T extends ComponentHarness > ( query : HarnessQuery < T > ) : Promise < T [ ] > ;
116
+
117
+ /**
118
+ * Searches for an instance of the component corresponding to the given harness type under the
119
+ * `HarnessLoader`'s root element, and returns a boolean indicating if any were found.
120
+ * @param query A query for a harness to create
121
+ * @return An instance of the given harness type (or null if not found).
122
+ */
123
+ hasHarness < T extends ComponentHarness > ( query : HarnessQuery < T > ) : Promise < boolean > ;
106
124
}
107
125
108
126
/**
@@ -403,10 +421,18 @@ export abstract class ContentContainerComponentHarness<S extends string = string
403
421
return ( await this . getRootHarnessLoader ( ) ) . getHarness ( query ) ;
404
422
}
405
423
424
+ async getOptionalHarness < T extends ComponentHarness > ( query : HarnessQuery < T > ) : Promise < T | null > {
425
+ return ( await this . getRootHarnessLoader ( ) ) . getOptionalHarness ( query ) ;
426
+ }
427
+
406
428
async getAllHarnesses < T extends ComponentHarness > ( query : HarnessQuery < T > ) : Promise < T [ ] > {
407
429
return ( await this . getRootHarnessLoader ( ) ) . getAllHarnesses ( query ) ;
408
430
}
409
431
432
+ async hasHarness < T extends ComponentHarness > ( query : HarnessQuery < T > ) : Promise < boolean > {
433
+ return ( await this . getRootHarnessLoader ( ) ) . hasHarness ( query ) ;
434
+ }
435
+
410
436
/**
411
437
* Gets the root harness loader from which to start
412
438
* searching for content contained by this harness.
0 commit comments