Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions types/__tests__/type-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ export async function testQueryHelpers() {
: includesAutomationId(content, automationId),
options,
)

const createIdRelatedErrorHandler =
(errorMessage: string, defaultErrorMessage: string) =>
<T>(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,
Expand All @@ -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')
Expand All @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions types/query-helpers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ export type BuiltQueryMethods<Arguments extends any[]> = [

export function buildQueries<Arguments extends any[]>(
queryAllBy: GetAllBy<Arguments>,
getMultipleError: GetErrorFunction,
getMissingError: GetErrorFunction,
getMultipleError: GetErrorFunction<Arguments>,
getMissingError: GetErrorFunction<Arguments>,
): BuiltQueryMethods<Arguments>