Skip to content

Commit 2779fd8

Browse files
committed
fix(types): allow all elements
1 parent 010f8be commit 2779fd8

11 files changed

+59
-59
lines changed

src/get-queries-for-element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as defaultQueries from './queries'
55
*/
66

77
/**
8-
* @param {HTMLElement} element container
8+
* @param {Element} element container
99
* @param {FuncMap} queries object of functions
1010
* @param {Object} initialValue for reducer
1111
* @returns {FuncMap} returns object of functions bound to container

types/__tests__/type-tests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export async function testQueryHelpers() {
5252
const includesAutomationId = (content: string, automationId: string) =>
5353
content.split(/\s+/).some(id => id === automationId)
5454
const queryAllByAutomationId = (
55-
container: HTMLElement,
55+
container: Element,
5656
automationId: string | string[],
5757
options?: MatcherOptions,
5858
) =>
@@ -138,7 +138,7 @@ export function eventTest() {
138138
state: {page: 1},
139139
})
140140

141-
// HTMLElement
141+
// Element
142142
const element = document.createElement('div')
143143
fireEvent.click(getByText(element, 'foo'))
144144

types/config.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface Config {
77
defaultHidden: boolean
88
showOriginalStackTrace: boolean
99
throwSuggestions: boolean
10-
getElementError: (message: string, container: HTMLElement) => Error
10+
getElementError: (message: string, container: Element) => Error
1111
}
1212

1313
export interface ConfigFn {

types/get-node-text.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export function getNodeText(node: HTMLElement): string;
1+
export function getNodeText(node: Element): string;

types/get-queries-for-element.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as queries from './queries';
22

33
export type BoundFunction<T> = T extends (
44
attribute: string,
5-
element: HTMLElement,
5+
element: Element,
66
text: infer P,
77
options: infer Q,
88
) => infer R
@@ -15,15 +15,15 @@ export type BoundFunction<T> = T extends (
1515
export type BoundFunctions<T> = { [P in keyof T]: BoundFunction<T[P]> };
1616

1717
export type Query = (
18-
container: HTMLElement,
18+
container: Element,
1919
...args: any[]
20-
) => Error | Promise<HTMLElement[]> | Promise<HTMLElement> | HTMLElement[] | HTMLElement | null;
20+
) => Error | Promise<Element[]> | Promise<Element> | Element[] | Element | null;
2121

2222
export interface Queries {
2323
[T: string]: Query;
2424
}
2525

2626
export function getQueriesForElement<T extends Queries = typeof queries>(
27-
element: HTMLElement,
27+
element: Element,
2828
queriesToBind?: T,
2929
): BoundFunctions<T>;

types/matches.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {ARIARole} from 'aria-query'
22

3-
export type MatcherFunction = (content: string, element: HTMLElement) => boolean
3+
export type MatcherFunction = (content: string, element: Element) => boolean
44
export type Matcher = MatcherFunction | {}
55

66
// Get autocomplete for ARIARole union types, while still supporting another string
@@ -22,7 +22,7 @@ export interface MatcherOptions {
2222

2323
export type Match = (
2424
textToMatch: string,
25-
node: HTMLElement | null,
25+
node: Element | null,
2626
matcher: Matcher,
2727
options?: MatcherOptions,
2828
) => boolean

types/queries.d.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,68 @@ import {SelectorMatcherOptions} from './query-helpers'
33
import {waitForOptions} from './wait-for'
44

55
export type QueryByBoundAttribute = (
6-
container: HTMLElement,
6+
container: Element,
77
id: Matcher,
88
options?: MatcherOptions,
9-
) => HTMLElement | null
9+
) => Element | null
1010

1111
export type AllByBoundAttribute = (
12-
container: HTMLElement,
12+
container: Element,
1313
id: Matcher,
1414
options?: MatcherOptions,
15-
) => HTMLElement[]
15+
) => Element[]
1616

1717
export type FindAllByBoundAttribute = (
18-
container: HTMLElement,
18+
container: Element,
1919
id: Matcher,
2020
options?: MatcherOptions,
2121
waitForElementOptions?: waitForOptions,
22-
) => Promise<HTMLElement[]>
22+
) => Promise<Element[]>
2323

2424
export type GetByBoundAttribute = (
25-
container: HTMLElement,
25+
container: Element,
2626
id: Matcher,
2727
options?: MatcherOptions,
28-
) => HTMLElement
28+
) => Element
2929

3030
export type FindByBoundAttribute = (
31-
container: HTMLElement,
31+
container: Element,
3232
id: Matcher,
3333
options?: MatcherOptions,
3434
waitForElementOptions?: waitForOptions,
35-
) => Promise<HTMLElement>
35+
) => Promise<Element>
3636

3737
export type QueryByText = (
38-
container: HTMLElement,
38+
container: Element,
3939
id: Matcher,
4040
options?: SelectorMatcherOptions,
41-
) => HTMLElement | null
41+
) => Element | null
4242

4343
export type AllByText = (
44-
container: HTMLElement,
44+
container: Element,
4545
id: Matcher,
4646
options?: SelectorMatcherOptions,
47-
) => HTMLElement[]
47+
) => Element[]
4848

4949
export type FindAllByText = (
50-
container: HTMLElement,
50+
container: Element,
5151
id: Matcher,
5252
options?: SelectorMatcherOptions,
5353
waitForElementOptions?: waitForOptions,
54-
) => Promise<HTMLElement[]>
54+
) => Promise<Element[]>
5555

5656
export type GetByText = (
57-
container: HTMLElement,
57+
container: Element,
5858
id: Matcher,
5959
options?: SelectorMatcherOptions,
60-
) => HTMLElement
60+
) => Element
6161

6262
export type FindByText = (
63-
container: HTMLElement,
63+
container: Element,
6464
id: Matcher,
6565
options?: SelectorMatcherOptions,
6666
waitForElementOptions?: waitForOptions,
67-
) => Promise<HTMLElement>
67+
) => Promise<Element>
6868

6969
export interface ByRoleOptions extends MatcherOptions {
7070
/**
@@ -109,36 +109,36 @@ export interface ByRoleOptions extends MatcherOptions {
109109
}
110110

111111
export type AllByRole = (
112-
container: HTMLElement,
112+
container: Element,
113113
role: ByRoleMatcher,
114114
options?: ByRoleOptions,
115-
) => HTMLElement[]
115+
) => Element[]
116116

117117
export type GetByRole = (
118-
container: HTMLElement,
118+
container: Element,
119119
role: ByRoleMatcher,
120120
options?: ByRoleOptions,
121-
) => HTMLElement
121+
) => Element
122122

123123
export type QueryByRole = (
124-
container: HTMLElement,
124+
container: Element,
125125
role: ByRoleMatcher,
126126
options?: ByRoleOptions,
127-
) => HTMLElement | null
127+
) => Element | null
128128

129129
export type FindByRole = (
130-
container: HTMLElement,
130+
container: Element,
131131
role: ByRoleMatcher,
132132
options?: ByRoleOptions,
133133
waitForElementOptions?: waitForOptions,
134-
) => Promise<HTMLElement>
134+
) => Promise<Element>
135135

136136
export type FindAllByRole = (
137-
container: HTMLElement,
137+
container: Element,
138138
role: ByRoleMatcher,
139139
options?: ByRoleOptions,
140140
waitForElementOptions?: waitForOptions,
141-
) => Promise<HTMLElement[]>
141+
) => Promise<Element[]>
142142

143143
export const getByLabelText: GetByText
144144
export const getAllByLabelText: AllByText

types/query-helpers.d.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,45 @@ export interface SelectorMatcherOptions extends MatcherOptions {
77

88
export type QueryByAttribute = (
99
attribute: string,
10-
container: HTMLElement,
10+
container: Element,
1111
id: Matcher,
1212
options?: MatcherOptions,
13-
) => HTMLElement | null
13+
) => Element | null
1414

1515
export type AllByAttribute = (
1616
attribute: string,
17-
container: HTMLElement,
17+
container: Element,
1818
id: Matcher,
1919
options?: MatcherOptions,
20-
) => HTMLElement[]
20+
) => Element[]
2121

2222
export const queryByAttribute: QueryByAttribute
2323
export const queryAllByAttribute: AllByAttribute
24-
export function getElementError(message: string, container: HTMLElement): Error
24+
export function getElementError(message: string, container: Element): Error
2525

2626
/**
2727
* query methods have a common call signature. Only the return type differs.
2828
*/
2929
export type QueryMethod<Arguments extends any[], Return> = (
30-
container: HTMLElement,
30+
container: Element,
3131
...args: Arguments
3232
) => Return
3333
export type QueryBy<Arguments extends any[]> = QueryMethod<
3434
Arguments,
35-
HTMLElement | null
35+
Element | null
3636
>
3737
export type GetAllBy<Arguments extends any[]> = QueryMethod<
3838
Arguments,
39-
HTMLElement[]
39+
Element[]
4040
>
4141
export type FindAllBy<Arguments extends any[]> = QueryMethod<
4242
[Arguments[0], Arguments[1]?, waitForOptions?],
43-
Promise<HTMLElement[]>
43+
Promise<Element[]>
4444
>
45-
export type GetBy<Arguments extends any[]> = QueryMethod<Arguments, HTMLElement>
45+
export type GetBy<Arguments extends any[]> = QueryMethod<Arguments, Element>
4646
export type FindBy<Arguments extends any[]> = QueryMethod<
4747
[Arguments[0], Arguments[1]?, waitForOptions?],
48-
Promise<HTMLElement>
48+
Promise<Element>
4949
>
5050

5151
export type BuiltQueryMethods<Arguments extends any[]> = [
@@ -57,6 +57,6 @@ export type BuiltQueryMethods<Arguments extends any[]> = [
5757
]
5858
export function buildQueries<Arguments extends any[]>(
5959
queryByAll: GetAllBy<Arguments>,
60-
getMultipleError: (container: HTMLElement, ...args: Arguments) => string,
61-
getMissingError: (container: HTMLElement, ...args: Arguments) => string,
60+
getMultipleError: (container: Element, ...args: Arguments) => string,
61+
getMissingError: (container: Element, ...args: Arguments) => string,
6262
): BuiltQueryMethods<Arguments>

types/role-helpers.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
export function logRoles(container: HTMLElement): string
1+
export function logRoles(container: Element): string
22
export function getRoles(
3-
container: HTMLElement,
4-
): {[index: string]: HTMLElement[]}
3+
container: Element,
4+
): {[index: string]: Element[]}
55
/**
66
* https://testing-library.com/docs/dom-testing-library/api-helpers#isinaccessible
77
*/

types/suggestions.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export type Method =
4040
| 'testid'
4141

4242
export function getSuggestedQuery(
43-
element: HTMLElement,
43+
element: Element,
4444
variant?: Variant,
4545
method?: Method,
4646
): Suggestion | undefined

types/wait-for.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export interface waitForOptions {
2-
container?: HTMLElement
2+
container?: Element
33
timeout?: number
44
interval?: number
55
onTimeout?: (error: Error) => Error

0 commit comments

Comments
 (0)