Skip to content

Commit edca54f

Browse files
committed
fix(cdk/testing): require at least one argument for locator functions (#23619)
Currently locator functions accept a spread argument which technically allows for zero selectors to be passed in. This can result in weird runtime errors. These changes add a runtime error if no selectors are passed in. Note that a previous iteration of these changes tried to enforce this with typings, but it resulted in breaking changes. (cherry picked from commit f592a43)
1 parent c47d30e commit edca54f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/cdk/testing/harness-environment.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ export abstract class HarnessEnvironment<E> implements HarnessLoader, LocatorFac
171171
private async _getAllHarnessesAndTestElements<T extends (HarnessQuery<any> | string)[]>(
172172
queries: T,
173173
): Promise<LocatorFnResult<T>[]> {
174+
if (!queries.length) {
175+
throw Error('CDK Component harness query must contain at least one element.');
176+
}
177+
174178
const {allQueries, harnessQueries, elementQueries, harnessTypes} = _parseQueries(queries);
175179

176180
// Combine all of the queries into one large comma-delimited selector and use it to get all raw

0 commit comments

Comments
 (0)