Skip to content

Commit 1a34a05

Browse files
committed
fix(cdk/testing): require at least one argument for locator functions
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.
1 parent 92863cc commit 1a34a05

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
@@ -181,6 +181,10 @@ export abstract class HarnessEnvironment<E> implements HarnessLoader, LocatorFac
181181
private async _getAllHarnessesAndTestElements<T extends (HarnessQuery<any> | string)[]>(
182182
queries: T,
183183
): Promise<LocatorFnResult<T>[]> {
184+
if (!queries.length) {
185+
throw Error('CDK Component harness query must contain at least one element.');
186+
}
187+
184188
const {allQueries, harnessQueries, elementQueries, harnessTypes} = _parseQueries(queries);
185189

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

0 commit comments

Comments
 (0)