Skip to content

Commit 6171979

Browse files
fix(buildQuery): get*Error functions receive same Arguments type as queryAllBy parameter (#1041)
1 parent 99bc2c0 commit 6171979

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

types/__tests__/type-tests.ts

+29-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ export async function testQueryHelpers() {
6868
: includesAutomationId(content, automationId),
6969
options,
7070
)
71+
72+
const createIdRelatedErrorHandler =
73+
(errorMessage: string, defaultErrorMessage: string) =>
74+
<T>(container: Element | null, ...args: T[]) => {
75+
const [key, value] = args
76+
if (!container) {
77+
return 'Container element not specified'
78+
}
79+
if (key && value) {
80+
return errorMessage
81+
.replace('[key]', String(key))
82+
.replace('[value]', String(value))
83+
}
84+
return defaultErrorMessage
85+
}
86+
7187
const [
7288
queryByAutomationId,
7389
getAllByAutomationId,
@@ -76,8 +92,14 @@ export async function testQueryHelpers() {
7692
findByAutomationId,
7793
] = buildQueries(
7894
queryAllByAutomationId,
79-
() => 'Multiple Error',
80-
() => 'Missing Error',
95+
createIdRelatedErrorHandler(
96+
`Found multiple with key [key] and value [value]`,
97+
'Multiple error',
98+
),
99+
createIdRelatedErrorHandler(
100+
`Unable to find an element with the [key] attribute of: [value]`,
101+
'Missing error',
102+
),
81103
)
82104
queryByAutomationId(element, 'id')
83105
getAllByAutomationId(element, 'id')
@@ -89,6 +111,11 @@ export async function testQueryHelpers() {
89111
await findByAutomationId(element, 'id', {})
90112
await findAllByAutomationId(element, 'id')
91113
await findByAutomationId(element, 'id')
114+
115+
await findAllByAutomationId(element, ['id', 'id'], {})
116+
await findByAutomationId(element, ['id', 'id'], {})
117+
await findAllByAutomationId(element, ['id', 'id'])
118+
await findByAutomationId(element, ['id', 'id'])
92119
}
93120

94121
export function testBoundFunctions() {

types/query-helpers.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ export type BuiltQueryMethods<Arguments extends any[]> = [
6969

7070
export function buildQueries<Arguments extends any[]>(
7171
queryAllBy: GetAllBy<Arguments>,
72-
getMultipleError: GetErrorFunction,
73-
getMissingError: GetErrorFunction,
72+
getMultipleError: GetErrorFunction<Arguments>,
73+
getMissingError: GetErrorFunction<Arguments>,
7474
): BuiltQueryMethods<Arguments>

0 commit comments

Comments
 (0)