diff --git a/types/__tests__/type-tests.ts b/types/__tests__/type-tests.ts index 4e1a4fb2..d4a22e77 100644 --- a/types/__tests__/type-tests.ts +++ b/types/__tests__/type-tests.ts @@ -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() { diff --git a/types/query-helpers.d.ts b/types/query-helpers.d.ts index 7b9904b1..c02a3558 100644 --- a/types/query-helpers.d.ts +++ b/types/query-helpers.d.ts @@ -50,12 +50,12 @@ export type GetAllBy = QueryMethod< HTMLElement[] > export type FindAllBy = QueryMethod< - [Arguments[0], Arguments[1]?, waitForOptions?], + [...Arguments, waitForOptions?], Promise > export type GetBy = QueryMethod export type FindBy = QueryMethod< - [Arguments[0], Arguments[1]?, waitForOptions?], + [...Arguments, waitForOptions?], Promise >