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

fix(within): Types should list custom and base queries #1045

Merged
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
15 changes: 15 additions & 0 deletions types/__tests__/type-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@ export async function testQueryHelpers() {
await findByAutomationId(element, ['id', 'id'], {})
await findAllByAutomationId(element, ['id', 'id'])
await findByAutomationId(element, ['id', 'id'])

const screenWithCustomQueries = within(document.body, {
...queries,
queryByAutomationId,
getAllByAutomationId,
getByAutomationId,
findAllByAutomationId,
findByAutomationId,
})

screenWithCustomQueries.queryByAutomationId('id')
screenWithCustomQueries.getAllByAutomationId('id')
screenWithCustomQueries.getByAutomationId(['id', 'automationId'])
await screenWithCustomQueries.findAllByAutomationId('id', {}, {timeout: 1000})
await screenWithCustomQueries.findByAutomationId('id', {}, {timeout: 1000})
}

export function testBoundFunctions() {
Expand Down
2 changes: 2 additions & 0 deletions types/get-queries-for-element.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ export type BoundFunctions<Q> = Q extends typeof queries
findAllByTestId<T extends HTMLElement = HTMLElement>(
...args: Parameters<BoundFunction<queries.FindAllByBoundAttribute<T>>>
): ReturnType<queries.FindAllByBoundAttribute<T>>
} & {
[P in keyof Q]: BoundFunction<Q[P]>
}
: {
[P in keyof Q]: BoundFunction<Q[P]>
Expand Down