Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In FindAllBy and FindAll query helper types: spread Arguments to support no arguments #1230

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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