|
1 | | -import {Matcher, MatcherOptions, ByRoleMatcher} from './matches' |
| 1 | +import {ByRoleMatcher, Matcher, MatcherOptions} from './matches' |
2 | 2 | import {SelectorMatcherOptions} from './query-helpers' |
3 | 3 | import {waitForOptions} from './wait-for' |
4 | 4 |
|
5 | | -export type QueryByBoundAttribute = ( |
| 5 | +export type QueryByBoundAttribute<T extends HTMLElement = HTMLElement> = ( |
6 | 6 | container: HTMLElement, |
7 | 7 | id: Matcher, |
8 | 8 | options?: MatcherOptions, |
9 | | -) => HTMLElement | null |
| 9 | +) => T | null |
10 | 10 |
|
11 | | -export type AllByBoundAttribute = ( |
| 11 | +export type AllByBoundAttribute<T extends HTMLElement = HTMLElement> = ( |
12 | 12 | container: HTMLElement, |
13 | 13 | id: Matcher, |
14 | 14 | options?: MatcherOptions, |
15 | | -) => HTMLElement[] |
| 15 | +) => T[] |
16 | 16 |
|
17 | | -export type FindAllByBoundAttribute = ( |
| 17 | +export type FindAllByBoundAttribute<T extends HTMLElement = HTMLElement> = ( |
18 | 18 | container: HTMLElement, |
19 | 19 | id: Matcher, |
20 | 20 | options?: MatcherOptions, |
21 | 21 | waitForElementOptions?: waitForOptions, |
22 | | -) => Promise<HTMLElement[]> |
| 22 | +) => Promise<T[]> |
23 | 23 |
|
24 | | -export type GetByBoundAttribute = ( |
| 24 | +export type GetByBoundAttribute<T extends HTMLElement = HTMLElement> = ( |
25 | 25 | container: HTMLElement, |
26 | 26 | id: Matcher, |
27 | 27 | options?: MatcherOptions, |
28 | | -) => HTMLElement |
| 28 | +) => T |
29 | 29 |
|
30 | | -export type FindByBoundAttribute = ( |
| 30 | +export type FindByBoundAttribute<T extends HTMLElement = HTMLElement> = ( |
31 | 31 | container: HTMLElement, |
32 | 32 | id: Matcher, |
33 | 33 | options?: MatcherOptions, |
34 | 34 | waitForElementOptions?: waitForOptions, |
35 | | -) => Promise<HTMLElement> |
| 35 | +) => Promise<T> |
36 | 36 |
|
37 | | -export type QueryByText = ( |
| 37 | +export type QueryByText<T extends HTMLElement = HTMLElement> = ( |
38 | 38 | container: HTMLElement, |
39 | 39 | id: Matcher, |
40 | 40 | options?: SelectorMatcherOptions, |
41 | | -) => HTMLElement | null |
| 41 | +) => T | null |
42 | 42 |
|
43 | | -export type AllByText = ( |
| 43 | +export type AllByText<T extends HTMLElement = HTMLElement> = ( |
44 | 44 | container: HTMLElement, |
45 | 45 | id: Matcher, |
46 | 46 | options?: SelectorMatcherOptions, |
47 | | -) => HTMLElement[] |
| 47 | +) => T[] |
48 | 48 |
|
49 | | -export type FindAllByText = ( |
| 49 | +export type FindAllByText<T extends HTMLElement = HTMLElement> = ( |
50 | 50 | container: HTMLElement, |
51 | 51 | id: Matcher, |
52 | 52 | options?: SelectorMatcherOptions, |
53 | 53 | waitForElementOptions?: waitForOptions, |
54 | | -) => Promise<HTMLElement[]> |
| 54 | +) => Promise<T[]> |
55 | 55 |
|
56 | | -export type GetByText = ( |
| 56 | +export type GetByText<T extends HTMLElement = HTMLElement> = ( |
57 | 57 | container: HTMLElement, |
58 | 58 | id: Matcher, |
59 | 59 | options?: SelectorMatcherOptions, |
60 | | -) => HTMLElement |
| 60 | +) => T |
61 | 61 |
|
62 | | -export type FindByText = ( |
| 62 | +export type FindByText<T extends HTMLElement = HTMLElement> = ( |
63 | 63 | container: HTMLElement, |
64 | 64 | id: Matcher, |
65 | 65 | options?: SelectorMatcherOptions, |
66 | 66 | waitForElementOptions?: waitForOptions, |
67 | | -) => Promise<HTMLElement> |
| 67 | +) => Promise<T> |
68 | 68 |
|
69 | 69 | export interface ByRoleOptions extends MatcherOptions { |
70 | 70 | /** |
@@ -117,83 +117,179 @@ export interface ByRoleOptions extends MatcherOptions { |
117 | 117 | | ((accessibleName: string, element: Element) => boolean) |
118 | 118 | } |
119 | 119 |
|
120 | | -export type AllByRole = ( |
| 120 | +export type AllByRole<T extends HTMLElement = HTMLElement> = ( |
121 | 121 | container: HTMLElement, |
122 | 122 | role: ByRoleMatcher, |
123 | 123 | options?: ByRoleOptions, |
124 | | -) => HTMLElement[] |
| 124 | +) => T[] |
125 | 125 |
|
126 | | -export type GetByRole = ( |
| 126 | +export type GetByRole<T extends HTMLElement = HTMLElement> = ( |
127 | 127 | container: HTMLElement, |
128 | 128 | role: ByRoleMatcher, |
129 | 129 | options?: ByRoleOptions, |
130 | | -) => HTMLElement |
| 130 | +) => T |
131 | 131 |
|
132 | | -export type QueryByRole = ( |
| 132 | +export type QueryByRole<T extends HTMLElement = HTMLElement> = ( |
133 | 133 | container: HTMLElement, |
134 | 134 | role: ByRoleMatcher, |
135 | 135 | options?: ByRoleOptions, |
136 | | -) => HTMLElement | null |
| 136 | +) => T | null |
137 | 137 |
|
138 | | -export type FindByRole = ( |
| 138 | +export type FindByRole<T extends HTMLElement = HTMLElement> = ( |
139 | 139 | container: HTMLElement, |
140 | 140 | role: ByRoleMatcher, |
141 | 141 | options?: ByRoleOptions, |
142 | 142 | waitForElementOptions?: waitForOptions, |
143 | | -) => Promise<HTMLElement> |
| 143 | +) => Promise<T> |
144 | 144 |
|
145 | | -export type FindAllByRole = ( |
| 145 | +export type FindAllByRole<T extends HTMLElement = HTMLElement> = ( |
146 | 146 | container: HTMLElement, |
147 | 147 | role: ByRoleMatcher, |
148 | 148 | options?: ByRoleOptions, |
149 | 149 | waitForElementOptions?: waitForOptions, |
150 | | -) => Promise<HTMLElement[]> |
151 | | - |
152 | | -export const getByLabelText: GetByText |
153 | | -export const getAllByLabelText: AllByText |
154 | | -export const queryByLabelText: QueryByText |
155 | | -export const queryAllByLabelText: AllByText |
156 | | -export const findByLabelText: FindByText |
157 | | -export const findAllByLabelText: FindAllByText |
158 | | -export const getByPlaceholderText: GetByBoundAttribute |
159 | | -export const getAllByPlaceholderText: AllByBoundAttribute |
160 | | -export const queryByPlaceholderText: QueryByBoundAttribute |
161 | | -export const queryAllByPlaceholderText: AllByBoundAttribute |
162 | | -export const findByPlaceholderText: FindByBoundAttribute |
163 | | -export const findAllByPlaceholderText: FindAllByBoundAttribute |
164 | | -export const getByText: GetByText |
165 | | -export const getAllByText: AllByText |
166 | | -export const queryByText: QueryByText |
167 | | -export const queryAllByText: AllByText |
168 | | -export const findByText: FindByText |
169 | | -export const findAllByText: FindAllByText |
170 | | -export const getByAltText: GetByBoundAttribute |
171 | | -export const getAllByAltText: AllByBoundAttribute |
172 | | -export const queryByAltText: QueryByBoundAttribute |
173 | | -export const queryAllByAltText: AllByBoundAttribute |
174 | | -export const findByAltText: FindByBoundAttribute |
175 | | -export const findAllByAltText: FindAllByBoundAttribute |
176 | | -export const getByTitle: GetByBoundAttribute |
177 | | -export const getAllByTitle: AllByBoundAttribute |
178 | | -export const queryByTitle: QueryByBoundAttribute |
179 | | -export const queryAllByTitle: AllByBoundAttribute |
180 | | -export const findByTitle: FindByBoundAttribute |
181 | | -export const findAllByTitle: FindAllByBoundAttribute |
182 | | -export const getByDisplayValue: GetByBoundAttribute |
183 | | -export const getAllByDisplayValue: AllByBoundAttribute |
184 | | -export const queryByDisplayValue: QueryByBoundAttribute |
185 | | -export const queryAllByDisplayValue: AllByBoundAttribute |
186 | | -export const findByDisplayValue: FindByBoundAttribute |
187 | | -export const findAllByDisplayValue: FindAllByBoundAttribute |
188 | | -export const getByRole: GetByRole |
189 | | -export const getAllByRole: AllByRole |
190 | | -export const queryByRole: QueryByRole |
191 | | -export const queryAllByRole: AllByRole |
192 | | -export const findByRole: FindByRole |
193 | | -export const findAllByRole: FindAllByRole |
194 | | -export const getByTestId: GetByBoundAttribute |
195 | | -export const getAllByTestId: AllByBoundAttribute |
196 | | -export const queryByTestId: QueryByBoundAttribute |
197 | | -export const queryAllByTestId: AllByBoundAttribute |
198 | | -export const findByTestId: FindByBoundAttribute |
199 | | -export const findAllByTestId: FindAllByBoundAttribute |
| 150 | +) => Promise<T[]> |
| 151 | + |
| 152 | +export function getByLabelText<T extends HTMLElement = HTMLElement>( |
| 153 | + ...args: Parameters<GetByText<T>> |
| 154 | +): ReturnType<GetByText<T>> |
| 155 | +export function getAllByLabelText<T extends HTMLElement = HTMLElement>( |
| 156 | + ...args: Parameters<AllByText<T>> |
| 157 | +): ReturnType<AllByText<T>> |
| 158 | +export function queryByLabelText<T extends HTMLElement = HTMLElement>( |
| 159 | + ...args: Parameters<QueryByText<T>> |
| 160 | +): ReturnType<QueryByText<T>> |
| 161 | +export function queryAllByLabelText<T extends HTMLElement = HTMLElement>( |
| 162 | + ...args: Parameters<AllByText<T>> |
| 163 | +): ReturnType<AllByText<T>> |
| 164 | +export function findByLabelText<T extends HTMLElement = HTMLElement>( |
| 165 | + ...args: Parameters<FindByText<T>> |
| 166 | +): ReturnType<FindByText<T>> |
| 167 | +export function findAllByLabelText<T extends HTMLElement = HTMLElement>( |
| 168 | + ...args: Parameters<FindAllByText<T>> |
| 169 | +): ReturnType<FindAllByText<T>> |
| 170 | +export function getByPlaceholderText<T extends HTMLElement = HTMLElement>( |
| 171 | + ...args: Parameters<GetByBoundAttribute<T>> |
| 172 | +): ReturnType<GetByBoundAttribute<T>> |
| 173 | +export function getAllByPlaceholderText<T extends HTMLElement = HTMLElement>( |
| 174 | + ...args: Parameters<AllByBoundAttribute<T>> |
| 175 | +): ReturnType<AllByBoundAttribute<T>> |
| 176 | +export function queryByPlaceholderText<T extends HTMLElement = HTMLElement>( |
| 177 | + ...args: Parameters<QueryByBoundAttribute<T>> |
| 178 | +): ReturnType<QueryByBoundAttribute<T>> |
| 179 | +export function queryAllByPlaceholderText<T extends HTMLElement = HTMLElement>( |
| 180 | + ...args: Parameters<AllByBoundAttribute<T>> |
| 181 | +): ReturnType<AllByBoundAttribute<T>> |
| 182 | +export function findByPlaceholderText<T extends HTMLElement = HTMLElement>( |
| 183 | + ...args: Parameters<FindByBoundAttribute<T>> |
| 184 | +): ReturnType<FindByBoundAttribute<T>> |
| 185 | +export function findAllByPlaceholderText<T extends HTMLElement = HTMLElement>( |
| 186 | + ...args: Parameters<FindAllByBoundAttribute<T>> |
| 187 | +): ReturnType<FindAllByBoundAttribute<T>> |
| 188 | +export function getByText<T extends HTMLElement = HTMLElement>( |
| 189 | + ...args: Parameters<GetByText<T>> |
| 190 | +): ReturnType<GetByText<T>> |
| 191 | +export function getAllByText<T extends HTMLElement = HTMLElement>( |
| 192 | + ...args: Parameters<AllByText<T>> |
| 193 | +): ReturnType<AllByText<T>> |
| 194 | +export function queryByText<T extends HTMLElement = HTMLElement>( |
| 195 | + ...args: Parameters<QueryByText<T>> |
| 196 | +): ReturnType<QueryByText<T>> |
| 197 | +export function queryAllByText<T extends HTMLElement = HTMLElement>( |
| 198 | + ...args: Parameters<AllByText<T>> |
| 199 | +): ReturnType<AllByText<T>> |
| 200 | +export function findByText<T extends HTMLElement = HTMLElement>( |
| 201 | + ...args: Parameters<FindByText<T>> |
| 202 | +): ReturnType<FindByText<T>> |
| 203 | +export function findAllByText<T extends HTMLElement = HTMLElement>( |
| 204 | + ...args: Parameters<FindAllByText<T>> |
| 205 | +): ReturnType<FindAllByText<T>> |
| 206 | +export function getByAltText<T extends HTMLElement = HTMLElement>( |
| 207 | + ...args: Parameters<GetByBoundAttribute<T>> |
| 208 | +): ReturnType<GetByBoundAttribute<T>> |
| 209 | +export function getAllByAltText<T extends HTMLElement = HTMLElement>( |
| 210 | + ...args: Parameters<AllByBoundAttribute<T>> |
| 211 | +): ReturnType<AllByBoundAttribute<T>> |
| 212 | +export function queryByAltText<T extends HTMLElement = HTMLElement>( |
| 213 | + ...args: Parameters<QueryByBoundAttribute<T>> |
| 214 | +): ReturnType<QueryByBoundAttribute<T>> |
| 215 | +export function queryAllByAltText<T extends HTMLElement = HTMLElement>( |
| 216 | + ...args: Parameters<AllByBoundAttribute<T>> |
| 217 | +): ReturnType<AllByBoundAttribute<T>> |
| 218 | +export function findByAltText<T extends HTMLElement = HTMLElement>( |
| 219 | + ...args: Parameters<FindByBoundAttribute<T>> |
| 220 | +): ReturnType<FindByBoundAttribute<T>> |
| 221 | +export function findAllByAltText<T extends HTMLElement = HTMLElement>( |
| 222 | + ...args: Parameters<FindAllByBoundAttribute<T>> |
| 223 | +): ReturnType<FindAllByBoundAttribute<T>> |
| 224 | +export function getByTitle<T extends HTMLElement = HTMLElement>( |
| 225 | + ...args: Parameters<GetByBoundAttribute<T>> |
| 226 | +): ReturnType<GetByBoundAttribute<T>> |
| 227 | +export function getAllByTitle<T extends HTMLElement = HTMLElement>( |
| 228 | + ...args: Parameters<AllByBoundAttribute<T>> |
| 229 | +): ReturnType<AllByBoundAttribute<T>> |
| 230 | +export function queryByTitle<T extends HTMLElement = HTMLElement>( |
| 231 | + ...args: Parameters<QueryByBoundAttribute<T>> |
| 232 | +): ReturnType<QueryByBoundAttribute<T>> |
| 233 | +export function queryAllByTitle<T extends HTMLElement = HTMLElement>( |
| 234 | + ...args: Parameters<AllByBoundAttribute<T>> |
| 235 | +): ReturnType<AllByBoundAttribute<T>> |
| 236 | +export function findByTitle<T extends HTMLElement = HTMLElement>( |
| 237 | + ...args: Parameters<FindByBoundAttribute<T>> |
| 238 | +): ReturnType<FindByBoundAttribute<T>> |
| 239 | +export function findAllByTitle<T extends HTMLElement = HTMLElement>( |
| 240 | + ...args: Parameters<FindAllByBoundAttribute<T>> |
| 241 | +): ReturnType<FindAllByBoundAttribute<T>> |
| 242 | +export function getByDisplayValue<T extends HTMLElement = HTMLElement>( |
| 243 | + ...args: Parameters<GetByBoundAttribute<T>> |
| 244 | +): ReturnType<GetByBoundAttribute<T>> |
| 245 | +export function getAllByDisplayValue<T extends HTMLElement = HTMLElement>( |
| 246 | + ...args: Parameters<AllByBoundAttribute<T>> |
| 247 | +): ReturnType<AllByBoundAttribute<T>> |
| 248 | +export function queryByDisplayValue<T extends HTMLElement = HTMLElement>( |
| 249 | + ...args: Parameters<QueryByBoundAttribute<T>> |
| 250 | +): ReturnType<QueryByBoundAttribute<T>> |
| 251 | +export function queryAllByDisplayValue<T extends HTMLElement = HTMLElement>( |
| 252 | + ...args: Parameters<AllByBoundAttribute<T>> |
| 253 | +): ReturnType<AllByBoundAttribute<T>> |
| 254 | +export function findByDisplayValue<T extends HTMLElement = HTMLElement>( |
| 255 | + ...args: Parameters<FindByBoundAttribute<T>> |
| 256 | +): ReturnType<FindByBoundAttribute<T>> |
| 257 | +export function findAllByDisplayValue<T extends HTMLElement = HTMLElement>( |
| 258 | + ...args: Parameters<FindAllByBoundAttribute<T>> |
| 259 | +): ReturnType<FindAllByBoundAttribute<T>> |
| 260 | +export function getByRole<T extends HTMLElement = HTMLElement>( |
| 261 | + ...args: Parameters<GetByRole<T>> |
| 262 | +): ReturnType<GetByRole<T>> |
| 263 | +export function getAllByRole<T extends HTMLElement = HTMLElement>( |
| 264 | + ...args: Parameters<AllByRole<T>> |
| 265 | +): ReturnType<AllByRole<T>> |
| 266 | +export function queryByRole<T extends HTMLElement = HTMLElement>( |
| 267 | + ...args: Parameters<QueryByRole<T>> |
| 268 | +): ReturnType<QueryByRole<T>> |
| 269 | +export function queryAllByRole<T extends HTMLElement = HTMLElement>( |
| 270 | + ...args: Parameters<AllByRole<T>> |
| 271 | +): ReturnType<AllByRole<T>> |
| 272 | +export function findByRole<T extends HTMLElement = HTMLElement>( |
| 273 | + ...args: Parameters<FindByRole<T>> |
| 274 | +): ReturnType<FindByRole<T>> |
| 275 | +export function findAllByRole<T extends HTMLElement = HTMLElement>( |
| 276 | + ...args: Parameters<FindAllByRole<T>> |
| 277 | +): ReturnType<FindAllByRole<T>> |
| 278 | +export function getByTestId<T extends HTMLElement = HTMLElement>( |
| 279 | + ...args: Parameters<GetByBoundAttribute<T>> |
| 280 | +): ReturnType<GetByBoundAttribute<T>> |
| 281 | +export function getAllByTestId<T extends HTMLElement = HTMLElement>( |
| 282 | + ...args: Parameters<AllByBoundAttribute<T>> |
| 283 | +): ReturnType<AllByBoundAttribute<T>> |
| 284 | +export function queryByTestId<T extends HTMLElement = HTMLElement>( |
| 285 | + ...args: Parameters<QueryByBoundAttribute<T>> |
| 286 | +): ReturnType<QueryByBoundAttribute<T>> |
| 287 | +export function queryAllByTestId<T extends HTMLElement = HTMLElement>( |
| 288 | + ...args: Parameters<AllByBoundAttribute<T>> |
| 289 | +): ReturnType<AllByBoundAttribute<T>> |
| 290 | +export function findByTestId<T extends HTMLElement = HTMLElement>( |
| 291 | + ...args: Parameters<FindByBoundAttribute<T>> |
| 292 | +): ReturnType<FindByBoundAttribute<T>> |
| 293 | +export function findAllByTestId<T extends HTMLElement = HTMLElement>( |
| 294 | + ...args: Parameters<FindAllByBoundAttribute<T>> |
| 295 | +): ReturnType<FindAllByBoundAttribute<T>> |
0 commit comments