Skip to content

Commit 0781b30

Browse files
committed
in FindAllBy and FindAll query helper types, spread Arguments to support no arguments
1 parent 39a64d4 commit 0781b30

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

types/__tests__/type-tests.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,50 @@ export async function testQueryHelpers() {
132132
screenWithCustomQueries.getByAutomationId(['id', 'automationId'])
133133
await screenWithCustomQueries.findAllByAutomationId('id', {}, {timeout: 1000})
134134
await screenWithCustomQueries.findByAutomationId('id', {}, {timeout: 1000})
135+
136+
// contrived example of a custom query with no arguments beyond container
137+
function queryAllByFoo(container: HTMLElement) {
138+
return queryAllByText(container, 'Foo')
139+
}
140+
141+
const [
142+
queryByTextFoo,
143+
getAllByTextFoo,
144+
getByTextFoo,
145+
findAllByTextFoo,
146+
findByTextFoo,
147+
] = buildQueries(
148+
queryAllByFoo,
149+
createIdRelatedErrorHandler(
150+
`Found multiple elements with text Foo`,
151+
'Multiple error',
152+
),
153+
createIdRelatedErrorHandler(
154+
`Unable to find an element with text Foo`,
155+
'Missing error',
156+
),
157+
)
158+
159+
queryByTextFoo(element)
160+
getAllByTextFoo(element)
161+
getByTextFoo(element)
162+
await findAllByTextFoo(element)
163+
await findByTextFoo(element)
164+
165+
const screenWithCustomFooQueries = within(document.body, {
166+
...queries,
167+
queryByTextFoo,
168+
getAllByTextFoo,
169+
getByTextFoo,
170+
findAllByTextFoo,
171+
findByTextFoo,
172+
})
173+
174+
screenWithCustomFooQueries.queryByTextFoo()
175+
screenWithCustomFooQueries.getAllByTextFoo()
176+
screenWithCustomFooQueries.getByTextFoo()
177+
await screenWithCustomFooQueries.findAllByTextFoo()
178+
await screenWithCustomFooQueries.findByTextFoo()
135179
}
136180

137181
export function testBoundFunctions() {

types/query-helpers.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ export type GetAllBy<Arguments extends any[]> = QueryMethod<
5050
HTMLElement[]
5151
>
5252
export type FindAllBy<Arguments extends any[]> = QueryMethod<
53-
[Arguments[0], Arguments[1]?, waitForOptions?],
53+
[...Arguments, waitForOptions?],
5454
Promise<HTMLElement[]>
5555
>
5656
export type GetBy<Arguments extends any[]> = QueryMethod<Arguments, HTMLElement>
5757
export type FindBy<Arguments extends any[]> = QueryMethod<
58-
[Arguments[0], Arguments[1]?, waitForOptions?],
58+
[...Arguments, waitForOptions?],
5959
Promise<HTMLElement>
6060
>
6161

0 commit comments

Comments
 (0)