From 6171979da2cfbca624f18a0a51efe63a3a213827 Mon Sep 17 00:00:00 2001 From: Jack Laurence Date: Thu, 30 Sep 2021 09:59:02 +0200 Subject: [PATCH] fix(buildQuery): get*Error functions receive same Arguments type as queryAllBy parameter (#1041) --- types/__tests__/type-tests.ts | 31 +++++++++++++++++++++++++++++-- types/query-helpers.d.ts | 4 ++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/types/__tests__/type-tests.ts b/types/__tests__/type-tests.ts index f3b69105..56be7993 100644 --- a/types/__tests__/type-tests.ts +++ b/types/__tests__/type-tests.ts @@ -68,6 +68,22 @@ export async function testQueryHelpers() { : includesAutomationId(content, automationId), options, ) + + const createIdRelatedErrorHandler = + (errorMessage: string, defaultErrorMessage: string) => + (container: Element | null, ...args: T[]) => { + const [key, value] = args + if (!container) { + return 'Container element not specified' + } + if (key && value) { + return errorMessage + .replace('[key]', String(key)) + .replace('[value]', String(value)) + } + return defaultErrorMessage + } + const [ queryByAutomationId, getAllByAutomationId, @@ -76,8 +92,14 @@ export async function testQueryHelpers() { findByAutomationId, ] = buildQueries( queryAllByAutomationId, - () => 'Multiple Error', - () => 'Missing Error', + createIdRelatedErrorHandler( + `Found multiple with key [key] and value [value]`, + 'Multiple error', + ), + createIdRelatedErrorHandler( + `Unable to find an element with the [key] attribute of: [value]`, + 'Missing error', + ), ) queryByAutomationId(element, 'id') getAllByAutomationId(element, 'id') @@ -89,6 +111,11 @@ export async function testQueryHelpers() { await findByAutomationId(element, 'id', {}) await findAllByAutomationId(element, 'id') await findByAutomationId(element, 'id') + + await findAllByAutomationId(element, ['id', 'id'], {}) + await findByAutomationId(element, ['id', 'id'], {}) + await findAllByAutomationId(element, ['id', 'id']) + await findByAutomationId(element, ['id', 'id']) } export function testBoundFunctions() { diff --git a/types/query-helpers.d.ts b/types/query-helpers.d.ts index 060be39c..7b9904b1 100644 --- a/types/query-helpers.d.ts +++ b/types/query-helpers.d.ts @@ -69,6 +69,6 @@ export type BuiltQueryMethods = [ export function buildQueries( queryAllBy: GetAllBy, - getMultipleError: GetErrorFunction, - getMissingError: GetErrorFunction, + getMultipleError: GetErrorFunction, + getMissingError: GetErrorFunction, ): BuiltQueryMethods