Skip to content

Commit e97e51c

Browse files
JaxCavaleraKent C. Dodds
authored and
Kent C. Dodds
committed
fix(TS): add findby type definitions (#231)
* [issue-226] included typescript definitions for find and findAll. Updated order of querie type definitions so they closer match order listed in documentation. * [issue-226] removed spaces generated by auto-formatting * [issue-226] included the | Error type for cases where the promise throws * [issue-226] removed unnecessary type definitions as those queries have been deprecated * [issue-226] Updated params to include 4th optional (waitForElementOptions) and extracted the interface so it can be shared between the 2 places where consumed.
1 parent 0137a17 commit e97e51c

File tree

2 files changed

+80
-33
lines changed

2 files changed

+80
-33
lines changed

typings/queries.d.ts

+73-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Matcher, MatcherOptions} from './matches'
22
import {SelectorMatcherOptions} from './query-helpers'
3+
import {WaitForElementOptions} from './wait-for-element'
34

45
export type QueryByBoundAttribute = (
56
container: HTMLElement,
@@ -13,12 +14,26 @@ export type AllByBoundAttribute = (
1314
options?: MatcherOptions,
1415
) => HTMLElement[]
1516

17+
export type FindAllByBoundAttribute = (
18+
container: HTMLElement,
19+
id: Matcher,
20+
options?: MatcherOptions,
21+
waitForElementOptions?: WaitForElementOptions
22+
) => Promise<HTMLElement[]> | Error
23+
1624
export type GetByBoundAttribute = (
1725
container: HTMLElement,
1826
id: Matcher,
1927
options?: MatcherOptions,
2028
) => HTMLElement
2129

30+
export type FindByBoundAttribute = (
31+
container: HTMLElement,
32+
id: Matcher,
33+
options?: MatcherOptions,
34+
waitForElementOptions?: WaitForElementOptions
35+
) => Promise<HTMLElement> | Error
36+
2237
export type QueryByText = (
2338
container: HTMLElement,
2439
id: Matcher,
@@ -31,49 +46,79 @@ export type AllByText = (
3146
options?: SelectorMatcherOptions,
3247
) => HTMLElement[]
3348

49+
export type FindAllByText = (
50+
container: HTMLElement,
51+
id: Matcher,
52+
options?: SelectorMatcherOptions,
53+
waitForElementOptions?: WaitForElementOptions
54+
) => Promise<HTMLElement[]> | Error
55+
3456
export type GetByText = (
3557
container: HTMLElement,
3658
id: Matcher,
3759
options?: SelectorMatcherOptions,
3860
) => HTMLElement
3961

40-
export const queryByPlaceholderText: QueryByBoundAttribute
41-
export const queryAllByPlaceholderText: AllByBoundAttribute
62+
export type FindByText = (
63+
container: HTMLElement,
64+
id: Matcher,
65+
options?: SelectorMatcherOptions,
66+
waitForElementOptions?: WaitForElementOptions
67+
) => Promise<HTMLElement> | Error
68+
69+
export const getByLabelText: GetByText
70+
export const getAllByLabelText: AllByText
71+
export const queryByLabelText: QueryByText
72+
export const queryAllByLabelText: AllByText
73+
export const findByLabelText: FindByText
74+
export const findAllByLabelText: FindAllByText
4275
export const getByPlaceholderText: GetByBoundAttribute
4376
export const getAllByPlaceholderText: AllByBoundAttribute
44-
export const queryBySelectText: QueryByBoundAttribute
45-
export const queryAllBySelectText: AllByBoundAttribute
46-
export const getBySelectText: GetByBoundAttribute
47-
export const getAllBySelectText: AllByBoundAttribute
48-
export const queryByText: QueryByText
49-
export const queryAllByText: AllByText
77+
export const queryByPlaceholderText: QueryByBoundAttribute
78+
export const queryAllByPlaceholderText: AllByBoundAttribute
79+
export const findByPlaceholderText: FindByBoundAttribute
80+
export const findAllByPlaceholderText: FindAllByBoundAttribute
5081
export const getByText: GetByText
5182
export const getAllByText: AllByText
52-
export const queryByLabelText: QueryByText
53-
export const queryAllByLabelText: AllByText
54-
export const getByLabelText: GetByText
55-
export const getAllByLabelText: AllByText
56-
export const queryByAltText: QueryByBoundAttribute
57-
export const queryAllByAltText: AllByBoundAttribute
83+
export const queryByText: QueryByText
84+
export const queryAllByText: AllByText
85+
export const findByText: FindByText
86+
export const findAllByText: FindAllByText
5887
export const getByAltText: GetByBoundAttribute
5988
export const getAllByAltText: AllByBoundAttribute
60-
export const queryByTestId: QueryByBoundAttribute
61-
export const queryAllByTestId: AllByBoundAttribute
62-
export const getByTestId: GetByBoundAttribute
63-
export const getAllByTestId: AllByBoundAttribute
64-
export const queryByTitle: QueryByBoundAttribute
65-
export const queryAllByTitle: AllByBoundAttribute
89+
export const queryByAltText: QueryByBoundAttribute
90+
export const queryAllByAltText: AllByBoundAttribute
91+
export const findByAltText: FindByBoundAttribute
92+
export const findAllByAltText: FindAllByBoundAttribute
6693
export const getByTitle: GetByBoundAttribute
6794
export const getAllByTitle: AllByBoundAttribute
68-
export const queryByValue: QueryByBoundAttribute
69-
export const queryAllByValue: AllByBoundAttribute
70-
export const getByValue: GetByBoundAttribute
71-
export const getAllByValue: AllByBoundAttribute
72-
export const queryByDisplayValue: QueryByBoundAttribute
73-
export const queryAllByDisplayValue: AllByBoundAttribute
95+
export const queryByTitle: QueryByBoundAttribute
96+
export const queryAllByTitle: AllByBoundAttribute
97+
export const findByTitle: FindByBoundAttribute
98+
export const findAllByTitle: FindAllByBoundAttribute
7499
export const getByDisplayValue: GetByBoundAttribute
75100
export const getAllByDisplayValue: AllByBoundAttribute
76-
export const queryByRole: QueryByBoundAttribute
77-
export const queryAllByRole: AllByBoundAttribute
101+
export const queryByDisplayValue: QueryByBoundAttribute
102+
export const queryAllByDisplayValue: AllByBoundAttribute
103+
export const findByDisplayValue: FindByBoundAttribute
104+
export const findAllByDisplayValue: FindAllByBoundAttribute
78105
export const getByRole: GetByBoundAttribute
79106
export const getAllByRole: AllByBoundAttribute
107+
export const queryByRole: QueryByBoundAttribute
108+
export const queryAllByRole: AllByBoundAttribute
109+
export const findByRole: FindByBoundAttribute
110+
export const findAllByRole: FindAllByBoundAttribute
111+
export const getByTestId: GetByBoundAttribute
112+
export const getAllByTestId: AllByBoundAttribute
113+
export const queryByTestId: QueryByBoundAttribute
114+
export const queryAllByTestId: AllByBoundAttribute
115+
export const findByTestId: FindByBoundAttribute
116+
export const findAllByTestId: FindAllByBoundAttribute
117+
export const getBySelectText: GetByBoundAttribute
118+
export const getAllBySelectText: AllByBoundAttribute
119+
export const queryBySelectText: QueryByBoundAttribute
120+
export const queryAllBySelectText: AllByBoundAttribute
121+
export const getByValue: GetByBoundAttribute
122+
export const getAllByValue: AllByBoundAttribute
123+
export const queryByValue: QueryByBoundAttribute
124+
export const queryAllByValue: AllByBoundAttribute

typings/wait-for-element.d.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
export interface WaitForElementOptions {
2+
container?: HTMLElement
3+
timeout?: number
4+
mutationObserverOptions?: MutationObserverInit
5+
}
6+
17
export function waitForElement<T>(
28
callback: () => T,
3-
options?: {
4-
container?: HTMLElement
5-
timeout?: number
6-
mutationObserverOptions?: MutationObserverInit
7-
},
9+
options?: WaitForElementOptions,
810
): Promise<T>

0 commit comments

Comments
 (0)