From 1a34a05df665a3c58345ced7713bc9bf73a8ec3f Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Mon, 7 Mar 2022 09:25:58 +0100 Subject: [PATCH] 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. --- src/cdk/testing/harness-environment.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cdk/testing/harness-environment.ts b/src/cdk/testing/harness-environment.ts index 277a842e7f19..671c5eccd8f2 100644 --- a/src/cdk/testing/harness-environment.ts +++ b/src/cdk/testing/harness-environment.ts @@ -181,6 +181,10 @@ export abstract class HarnessEnvironment implements HarnessLoader, LocatorFac private async _getAllHarnessesAndTestElements | string)[]>( queries: T, ): Promise[]> { + if (!queries.length) { + throw Error('CDK Component harness query must contain at least one element.'); + } + const {allQueries, harnessQueries, elementQueries, harnessTypes} = _parseQueries(queries); // Combine all of the queries into one large comma-delimited selector and use it to get all raw