forked from testing-library/dom-testing-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery-helpers.d.ts
98 lines (88 loc) · 2.65 KB
/
query-helpers.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import {Matcher, MatcherOptions} from './matches'
import {waitForOptions} from './wait-for'
export type WithSuggest = {suggest?: boolean}
export type GetErrorFunction<Arguments extends any[] = [string]> = (
c: Element | null,
...args: Arguments
) => string
export interface SelectorMatcherOptions extends MatcherOptions {
selector?: string
ignore?: boolean | string
}
export type QueryByAttribute = (
attribute: string,
container: HTMLElement,
id: Matcher,
options?: MatcherOptions,
) => HTMLElement | null
export type AllByAttribute = (
attribute: string,
container: HTMLElement,
id: Matcher,
options?: MatcherOptions,
) => HTMLElement[]
export const queryByAttribute: QueryByAttribute
export const queryAllByAttribute: AllByAttribute
export function getElementError(
message: string | null,
container: HTMLElement,
): Error
/**
* query methods have a common call signature. Only the return type differs.
*/
export type QueryMethod<Arguments extends any[], Return> = (
container: HTMLElement,
...args: Arguments
) => Return
export type QueryBy<Arguments extends any[]> = QueryMethod<
Arguments,
HTMLElement | null
>
export type GetAllBy<Arguments extends any[]> = QueryMethod<
Arguments,
HTMLElement[]
>
export type FindAllBy<Arguments extends any[]> = QueryMethod<
[Arguments[0], Arguments[1]?, waitForOptions?],
Promise<HTMLElement[]>
>
export type GetBy<Arguments extends any[]> = QueryMethod<Arguments, HTMLElement>
export type FindBy<Arguments extends any[]> = QueryMethod<
[Arguments[0], Arguments[1]?, waitForOptions?],
Promise<HTMLElement>
>
export type BuiltQueryMethods<Arguments extends any[]> = [
QueryBy<Arguments>,
GetAllBy<Arguments>,
GetBy<Arguments>,
FindAllBy<Arguments>,
FindBy<Arguments>,
]
export function buildQueries<Arguments extends any[]>(
queryAllBy: GetAllBy<Arguments>,
getMultipleError: GetErrorFunction<Arguments>,
getMissingError: GetErrorFunction<Arguments>,
): BuiltQueryMethods<Arguments>
export type QueryElement = {
<T, K extends keyof HTMLElementTagNameMap>(container: T, selectors: K):
| HTMLElementTagNameMap[K]
| null
<T, K extends keyof SVGElementTagNameMap>(container: T, selectors: K):
| SVGElementTagNameMap[K]
| null
<T, E extends Element = Element>(container: T, selectors: string): E | null
}
export type QueryAllElements = {
<T, K extends keyof HTMLElementTagNameMap>(
container: T,
selectors: K,
): NodeListOf<HTMLElementTagNameMap[K]>
<T, K extends keyof SVGElementTagNameMap>(
container: T,
selectors: K,
): NodeListOf<SVGElementTagNameMap[K]>
<T, E extends Element = Element>(
container: T,
selectors: string,
): NodeListOf<E>
}