Skip to content
Open
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
44 changes: 44 additions & 0 deletions types/__tests__/type-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,50 @@ export async function testQueryHelpers() {
screenWithCustomQueries.getByAutomationId(['id', 'automationId'])
await screenWithCustomQueries.findAllByAutomationId('id', {}, {timeout: 1000})
await screenWithCustomQueries.findByAutomationId('id', {}, {timeout: 1000})

// contrived example of a custom query with no arguments beyond container
function queryAllByFoo(container: HTMLElement) {
return queryAllByText(container, 'Foo')
}

const [
queryByTextFoo,
getAllByTextFoo,
getByTextFoo,
findAllByTextFoo,
findByTextFoo,
] = buildQueries(
queryAllByFoo,
createIdRelatedErrorHandler(
`Found multiple elements with text Foo`,
'Multiple error',
),
createIdRelatedErrorHandler(
`Unable to find an element with text Foo`,
'Missing error',
),
)

queryByTextFoo(element)
getAllByTextFoo(element)
getByTextFoo(element)
await findAllByTextFoo(element)
await findByTextFoo(element)

const screenWithCustomFooQueries = within(document.body, {
...queries,
queryByTextFoo,
getAllByTextFoo,
getByTextFoo,
findAllByTextFoo,
findByTextFoo,
})

screenWithCustomFooQueries.queryByTextFoo()
screenWithCustomFooQueries.getAllByTextFoo()
screenWithCustomFooQueries.getByTextFoo()
await screenWithCustomFooQueries.findAllByTextFoo()
await screenWithCustomFooQueries.findByTextFoo()
}

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 @@ -50,12 +50,12 @@ export type GetAllBy<Arguments extends any[]> = QueryMethod<
HTMLElement[]
>
export type FindAllBy<Arguments extends any[]> = QueryMethod<
[Arguments[0], Arguments[1]?, waitForOptions?],
[...Arguments, waitForOptions?],
Promise<HTMLElement[]>
>
export type GetBy<Arguments extends any[]> = QueryMethod<Arguments, HTMLElement>
export type FindBy<Arguments extends any[]> = QueryMethod<
[Arguments[0], Arguments[1]?, waitForOptions?],
[...Arguments, waitForOptions?],
Promise<HTMLElement>
>

Expand Down