Skip to content

Pr/issue 226 findby type definitions #231

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

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
101 changes: 73 additions & 28 deletions typings/queries.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Matcher, MatcherOptions} from './matches'
import {SelectorMatcherOptions} from './query-helpers'
import {WaitForElementOptions} from './wait-for-element'

export type QueryByBoundAttribute = (
container: HTMLElement,
Expand All @@ -13,12 +14,26 @@ export type AllByBoundAttribute = (
options?: MatcherOptions,
) => HTMLElement[]

export type FindAllByBoundAttribute = (
container: HTMLElement,
id: Matcher,
options?: MatcherOptions,
waitForElementOptions?: WaitForElementOptions
) => Promise<HTMLElement[]> | Error

export type GetByBoundAttribute = (
container: HTMLElement,
id: Matcher,
options?: MatcherOptions,
) => HTMLElement

export type FindByBoundAttribute = (
container: HTMLElement,
id: Matcher,
options?: MatcherOptions,
waitForElementOptions?: WaitForElementOptions
) => Promise<HTMLElement> | Error

export type QueryByText = (
container: HTMLElement,
id: Matcher,
Expand All @@ -31,49 +46,79 @@ export type AllByText = (
options?: SelectorMatcherOptions,
) => HTMLElement[]

export type FindAllByText = (
container: HTMLElement,
id: Matcher,
options?: SelectorMatcherOptions,
waitForElementOptions?: WaitForElementOptions
) => Promise<HTMLElement[]> | Error

export type GetByText = (
container: HTMLElement,
id: Matcher,
options?: SelectorMatcherOptions,
) => HTMLElement

export const queryByPlaceholderText: QueryByBoundAttribute
export const queryAllByPlaceholderText: AllByBoundAttribute
export type FindByText = (
container: HTMLElement,
id: Matcher,
options?: SelectorMatcherOptions,
waitForElementOptions?: WaitForElementOptions
) => Promise<HTMLElement> | Error

export const getByLabelText: GetByText
export const getAllByLabelText: AllByText
export const queryByLabelText: QueryByText
export const queryAllByLabelText: AllByText
export const findByLabelText: FindByText
export const findAllByLabelText: FindAllByText
export const getByPlaceholderText: GetByBoundAttribute
export const getAllByPlaceholderText: AllByBoundAttribute
export const queryBySelectText: QueryByBoundAttribute
export const queryAllBySelectText: AllByBoundAttribute
export const getBySelectText: GetByBoundAttribute
export const getAllBySelectText: AllByBoundAttribute
export const queryByText: QueryByText
export const queryAllByText: AllByText
export const queryByPlaceholderText: QueryByBoundAttribute
export const queryAllByPlaceholderText: AllByBoundAttribute
export const findByPlaceholderText: FindByBoundAttribute
export const findAllByPlaceholderText: FindAllByBoundAttribute
export const getByText: GetByText
export const getAllByText: AllByText
export const queryByLabelText: QueryByText
export const queryAllByLabelText: AllByText
export const getByLabelText: GetByText
export const getAllByLabelText: AllByText
export const queryByAltText: QueryByBoundAttribute
export const queryAllByAltText: AllByBoundAttribute
export const queryByText: QueryByText
export const queryAllByText: AllByText
export const findByText: FindByText
export const findAllByText: FindAllByText
export const getByAltText: GetByBoundAttribute
export const getAllByAltText: AllByBoundAttribute
export const queryByTestId: QueryByBoundAttribute
export const queryAllByTestId: AllByBoundAttribute
export const getByTestId: GetByBoundAttribute
export const getAllByTestId: AllByBoundAttribute
export const queryByTitle: QueryByBoundAttribute
export const queryAllByTitle: AllByBoundAttribute
export const queryByAltText: QueryByBoundAttribute
export const queryAllByAltText: AllByBoundAttribute
export const findByAltText: FindByBoundAttribute
export const findAllByAltText: FindAllByBoundAttribute
export const getByTitle: GetByBoundAttribute
export const getAllByTitle: AllByBoundAttribute
export const queryByValue: QueryByBoundAttribute
export const queryAllByValue: AllByBoundAttribute
export const getByValue: GetByBoundAttribute
export const getAllByValue: AllByBoundAttribute
export const queryByDisplayValue: QueryByBoundAttribute
export const queryAllByDisplayValue: AllByBoundAttribute
export const queryByTitle: QueryByBoundAttribute
export const queryAllByTitle: AllByBoundAttribute
export const findByTitle: FindByBoundAttribute
export const findAllByTitle: FindAllByBoundAttribute
export const getByDisplayValue: GetByBoundAttribute
export const getAllByDisplayValue: AllByBoundAttribute
export const queryByRole: QueryByBoundAttribute
export const queryAllByRole: AllByBoundAttribute
export const queryByDisplayValue: QueryByBoundAttribute
export const queryAllByDisplayValue: AllByBoundAttribute
export const findByDisplayValue: FindByBoundAttribute
export const findAllByDisplayValue: FindAllByBoundAttribute
export const getByRole: GetByBoundAttribute
export const getAllByRole: AllByBoundAttribute
export const queryByRole: QueryByBoundAttribute
export const queryAllByRole: AllByBoundAttribute
export const findByRole: FindByBoundAttribute
export const findAllByRole: FindAllByBoundAttribute
export const getByTestId: GetByBoundAttribute
export const getAllByTestId: AllByBoundAttribute
export const queryByTestId: QueryByBoundAttribute
export const queryAllByTestId: AllByBoundAttribute
export const findByTestId: FindByBoundAttribute
export const findAllByTestId: FindAllByBoundAttribute
export const getBySelectText: GetByBoundAttribute
export const getAllBySelectText: AllByBoundAttribute
export const queryBySelectText: QueryByBoundAttribute
export const queryAllBySelectText: AllByBoundAttribute
export const getByValue: GetByBoundAttribute
export const getAllByValue: AllByBoundAttribute
export const queryByValue: QueryByBoundAttribute
export const queryAllByValue: AllByBoundAttribute
12 changes: 7 additions & 5 deletions typings/wait-for-element.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
export interface WaitForElementOptions {
container?: HTMLElement
timeout?: number
mutationObserverOptions?: MutationObserverInit
}

export function waitForElement<T>(
callback: () => T,
options?: {
container?: HTMLElement
timeout?: number
mutationObserverOptions?: MutationObserverInit
},
options?: WaitForElementOptions,
): Promise<T>