|
1 |
| -import * as queries from './queries'; |
2 |
| - |
3 |
| -export type BoundFunction<T> = T extends ( |
4 |
| - attribute: string, |
5 |
| - element: HTMLElement, |
6 |
| - text: infer P, |
7 |
| - options: infer Q, |
8 |
| -) => infer R |
9 |
| - ? (text: P, options?: Q) => R |
10 |
| - : T extends (a1: any, text: infer P, options: infer Q, waitForElementOptions: infer W) => infer R |
11 |
| - ? (text: P, options?: Q, waitForElementOptions?: W) => R |
12 |
| - : T extends (a1: any, text: infer P, options: infer Q) => infer R |
13 |
| - ? (text: P, options?: Q) => R |
14 |
| - : never; |
15 |
| -export type BoundFunctions<T> = { [P in keyof T]: BoundFunction<T[P]> }; |
| 1 | +import * as queries from './queries' |
| 2 | +import {Matcher, ByRoleOptions, MatcherOptions} from './matches' |
| 3 | +import {waitForOptions} from './wait-for' |
| 4 | +import {ARIARole} from 'aria-query' |
| 5 | +import {SelectorMatcherOptions} from './query-helpers' |
| 6 | + |
| 7 | +export type QueryByBoundAttributeForElement = ( |
| 8 | + id: Matcher, |
| 9 | + options?: MatcherOptions, |
| 10 | +) => HTMLElement | null |
| 11 | + |
| 12 | +export type AllByBoundAttributeForElement = ( |
| 13 | + id: Matcher, |
| 14 | + options?: MatcherOptions, |
| 15 | +) => HTMLElement[] |
| 16 | + |
| 17 | +export type FindAllByBoundAttributeForElement = ( |
| 18 | + id: Matcher, |
| 19 | + options?: MatcherOptions, |
| 20 | + waitForElementOptions?: waitForOptions, |
| 21 | +) => Promise<HTMLElement[]> |
| 22 | + |
| 23 | +export type GetByBoundAttributeForElement = ( |
| 24 | + id: Matcher, |
| 25 | + options?: MatcherOptions, |
| 26 | +) => HTMLElement |
| 27 | + |
| 28 | +export type FindByBoundAttributeForElement = ( |
| 29 | + id: Matcher, |
| 30 | + options?: MatcherOptions, |
| 31 | + waitForElementOptions?: waitForOptions, |
| 32 | +) => Promise<HTMLElement> |
| 33 | + |
| 34 | +export type QueryByTextForElement = ( |
| 35 | + id: Matcher, |
| 36 | + options?: SelectorMatcherOptions, |
| 37 | +) => HTMLElement | null |
| 38 | + |
| 39 | +export type AllByTextForElement = ( |
| 40 | + id: Matcher, |
| 41 | + options?: SelectorMatcherOptions, |
| 42 | +) => HTMLElement[] |
| 43 | + |
| 44 | +export type FindAllByTextForElement = ( |
| 45 | + id: Matcher, |
| 46 | + options?: SelectorMatcherOptions, |
| 47 | + waitForElementOptions?: waitForOptions, |
| 48 | +) => Promise<HTMLElement[]> |
| 49 | + |
| 50 | +export type GetByTextForElement = ( |
| 51 | + id: Matcher, |
| 52 | + options?: SelectorMatcherOptions, |
| 53 | +) => HTMLElement |
| 54 | + |
| 55 | +export type FindByTextForElement = ( |
| 56 | + id: Matcher, |
| 57 | + options?: SelectorMatcherOptions, |
| 58 | + waitForElementOptions?: waitForOptions, |
| 59 | +) => Promise<HTMLElement> |
| 60 | + |
| 61 | +// disable unified-signatures to have intellisense for aria roles |
| 62 | +/* tslint:disable:unified-signatures */ |
| 63 | +export function AllByRoleForElement( |
| 64 | + role: Matcher, |
| 65 | + options?: ByRoleOptions, |
| 66 | +): HTMLElement[] |
| 67 | +export function AllByRoleForElement( |
| 68 | + role: ARIARole, |
| 69 | + options?: ByRoleOptions, |
| 70 | +): HTMLElement[] |
| 71 | + |
| 72 | +export function GetByRoleForElement( |
| 73 | + role: Matcher, |
| 74 | + options?: ByRoleOptions, |
| 75 | +): HTMLElement |
| 76 | +export function GetByRoleForElement( |
| 77 | + role: ARIARole, |
| 78 | + options?: ByRoleOptions, |
| 79 | +): HTMLElement |
| 80 | + |
| 81 | +export function QueryByRoleForElement( |
| 82 | + role: Matcher | ByRoleOptions, |
| 83 | + options?: ByRoleOptions, |
| 84 | +): HTMLElement | null |
| 85 | +export function QueryByRoleForElement( |
| 86 | + role: ARIARole, |
| 87 | + options?: ByRoleOptions, |
| 88 | +): HTMLElement | null |
| 89 | + |
| 90 | +export function FindByRoleForElement( |
| 91 | + role: Matcher, |
| 92 | + options?: ByRoleOptions, |
| 93 | + waitForElementOptions?: waitForOptions, |
| 94 | +): Promise<HTMLElement> |
| 95 | +export function FindByRoleForElement( |
| 96 | + role: ARIARole, |
| 97 | + options?: ByRoleOptions, |
| 98 | + waitForElementOptions?: waitForOptions, |
| 99 | +): Promise<HTMLElement> |
| 100 | + |
| 101 | +export function FindAllByRoleForElement( |
| 102 | + role: Matcher, |
| 103 | + options?: ByRoleOptions, |
| 104 | + waitForElementOptions?: waitForOptions, |
| 105 | +): Promise<HTMLElement[]> |
| 106 | +export function FindAllByRoleForElement( |
| 107 | + role: Matcher, |
| 108 | + options?: ByRoleOptions, |
| 109 | + waitForElementOptions?: waitForOptions, |
| 110 | +): Promise<HTMLElement[]> |
| 111 | + |
| 112 | +export interface BoundFunctions { |
| 113 | + getByLabelText: GetByTextForElement |
| 114 | + getAllByLabelText: AllByTextForElement |
| 115 | + queryByLabelText: QueryByTextForElement |
| 116 | + queryAllByLabelText: AllByTextForElement |
| 117 | + findByLabelText: FindByTextForElement |
| 118 | + findAllByLabelText: FindAllByTextForElement |
| 119 | + getByPlaceholderText: GetByBoundAttributeForElement |
| 120 | + getAllByPlaceholderText: AllByBoundAttributeForElement |
| 121 | + queryByPlaceholderText: QueryByBoundAttributeForElement |
| 122 | + queryAllByPlaceholderText: AllByBoundAttributeForElement |
| 123 | + findByPlaceholderText: FindByBoundAttributeForElement |
| 124 | + findAllByPlaceholderText: FindAllByBoundAttributeForElement |
| 125 | + getByText: GetByTextForElement |
| 126 | + getAllByText: AllByTextForElement |
| 127 | + queryByText: QueryByTextForElement |
| 128 | + queryAllByText: AllByTextForElement |
| 129 | + findByText: FindByTextForElement |
| 130 | + findAllByText: FindAllByTextForElement |
| 131 | + getByAltText: GetByBoundAttributeForElement |
| 132 | + getAllByAltText: AllByBoundAttributeForElement |
| 133 | + queryByAltText: QueryByBoundAttributeForElement |
| 134 | + queryAllByAltText: AllByBoundAttributeForElement |
| 135 | + findByAltText: FindByBoundAttributeForElement |
| 136 | + findAllByAltText: FindAllByBoundAttributeForElement |
| 137 | + getByTitle: GetByBoundAttributeForElement |
| 138 | + getAllByTitle: AllByBoundAttributeForElement |
| 139 | + queryByTitle: QueryByBoundAttributeForElement |
| 140 | + queryAllByTitle: AllByBoundAttributeForElement |
| 141 | + findByTitle: FindByBoundAttributeForElement |
| 142 | + findAllByTitle: FindAllByBoundAttributeForElement |
| 143 | + getByDisplayValue: GetByBoundAttributeForElement |
| 144 | + getAllByDisplayValue: AllByBoundAttributeForElement |
| 145 | + queryByDisplayValue: QueryByBoundAttributeForElement |
| 146 | + queryAllByDisplayValue: AllByBoundAttributeForElement |
| 147 | + findByDisplayValue: FindByBoundAttributeForElement |
| 148 | + findAllByDisplayValue: FindAllByBoundAttributeForElement |
| 149 | + getByRole: typeof GetByRoleForElement |
| 150 | + getAllByRole: typeof AllByRoleForElement |
| 151 | + queryByRole: typeof QueryByRoleForElement |
| 152 | + queryAllByRole: typeof AllByRoleForElement |
| 153 | + findByRole: typeof FindByRoleForElement |
| 154 | + findAllByRole: typeof FindAllByRoleForElement |
| 155 | + getByTestId: GetByBoundAttributeForElement |
| 156 | + getAllByTestId: AllByBoundAttributeForElement |
| 157 | + queryByTestId: QueryByBoundAttributeForElement |
| 158 | + queryAllByTestId: AllByBoundAttributeForElement |
| 159 | + findByTestId: FindByBoundAttributeForElement |
| 160 | + findAllByTestId: FindAllByBoundAttributeForElement |
| 161 | +} |
16 | 162 |
|
17 | 163 | export type Query = (
|
18 |
| - container: HTMLElement, |
19 |
| - ...args: any[] |
20 |
| -) => Error | Promise<HTMLElement[]> | Promise<HTMLElement> | HTMLElement[] | HTMLElement | null; |
| 164 | + container: HTMLElement, |
| 165 | + ...args: any[] |
| 166 | +) => |
| 167 | + | Error |
| 168 | + | Promise<HTMLElement[]> |
| 169 | + | Promise<HTMLElement> |
| 170 | + | HTMLElement[] |
| 171 | + | HTMLElement |
| 172 | + | null |
21 | 173 |
|
22 | 174 | export interface Queries {
|
23 |
| - [T: string]: Query; |
| 175 | + [T: string]: Query |
24 | 176 | }
|
25 | 177 |
|
26 |
| -export function getQueriesForElement<T extends Queries = typeof queries>( |
27 |
| - element: HTMLElement, |
28 |
| - queriesToBind?: T, |
29 |
| -): BoundFunctions<T>; |
| 178 | +export function getQueriesForElement( |
| 179 | + element: HTMLElement, |
| 180 | + queriesToBind?: typeof queries, |
| 181 | +): BoundFunctions |
0 commit comments