diff --git a/package.json b/package.json index 11a3b6cc..03a83da6 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,8 @@ "import/prefer-default-export": "off", "import/no-unassigned-import": "off", "import/no-useless-path-segments": "off", - "no-console": "off" + "no-console": "off", + "jest-dom/prefer-in-document": "off" } }, "eslintIgnore": [ diff --git a/src/get-queries-for-element.js b/src/get-queries-for-element.js index cc81578b..0b0c56ba 100644 --- a/src/get-queries-for-element.js +++ b/src/get-queries-for-element.js @@ -5,7 +5,7 @@ import * as defaultQueries from './queries' */ /** - * @param {HTMLElement} element container + * @param {Element} element container * @param {FuncMap} queries object of functions * @param {Object} initialValue for reducer * @returns {FuncMap} returns object of functions bound to container diff --git a/types/__tests__/type-tests.ts b/types/__tests__/type-tests.ts index 10fcd540..c8161580 100644 --- a/types/__tests__/type-tests.ts +++ b/types/__tests__/type-tests.ts @@ -52,7 +52,7 @@ export async function testQueryHelpers() { const includesAutomationId = (content: string, automationId: string) => content.split(/\s+/).some(id => id === automationId) const queryAllByAutomationId = ( - container: HTMLElement, + container: Element, automationId: string | string[], options?: MatcherOptions, ) => @@ -138,7 +138,7 @@ export function eventTest() { state: {page: 1}, }) - // HTMLElement + // Element const element = document.createElement('div') fireEvent.click(getByText(element, 'foo')) @@ -161,9 +161,7 @@ export async function testWaitFors() { await waitFor(() => getByText(element, 'apple')) await waitFor(() => getAllByText(element, 'apple')) - const result: HTMLSpanElement = await waitFor(() => - getByText(element, 'apple'), - ) + const result: Element = await waitFor(() => getByText(element, 'apple')) if (!result) { // Use value throw new Error(`Can't find result`) @@ -185,4 +183,5 @@ export async function testWaitFors() { /* eslint @typescript-eslint/no-unnecessary-condition: "off", + import/no-extraneous-dependencies: "off", */ diff --git a/types/config.d.ts b/types/config.d.ts index c93237a2..8bab54a9 100644 --- a/types/config.d.ts +++ b/types/config.d.ts @@ -7,7 +7,7 @@ export interface Config { defaultHidden: boolean showOriginalStackTrace: boolean throwSuggestions: boolean - getElementError: (message: string, container: HTMLElement) => Error + getElementError: (message: string, container: Element) => Error } export interface ConfigFn { diff --git a/types/get-node-text.d.ts b/types/get-node-text.d.ts index 5c5654b5..7e556db0 100644 --- a/types/get-node-text.d.ts +++ b/types/get-node-text.d.ts @@ -1 +1 @@ -export function getNodeText(node: HTMLElement): string; +export function getNodeText(node: Element): string; diff --git a/types/get-queries-for-element.d.ts b/types/get-queries-for-element.d.ts index b93adfe1..159d5d28 100644 --- a/types/get-queries-for-element.d.ts +++ b/types/get-queries-for-element.d.ts @@ -2,7 +2,7 @@ import * as queries from './queries'; export type BoundFunction = T extends ( attribute: string, - element: HTMLElement, + element: Element, text: infer P, options: infer Q, ) => infer R @@ -15,15 +15,15 @@ export type BoundFunction = T extends ( export type BoundFunctions = { [P in keyof T]: BoundFunction }; export type Query = ( - container: HTMLElement, + container: Element, ...args: any[] -) => Error | Promise | Promise | HTMLElement[] | HTMLElement | null; +) => Error | Promise | Promise | Element[] | Element | null; export interface Queries { [T: string]: Query; } export function getQueriesForElement( - element: HTMLElement, + element: Element, queriesToBind?: T, ): BoundFunctions; diff --git a/types/matches.d.ts b/types/matches.d.ts index d4da667b..b6299dc4 100644 --- a/types/matches.d.ts +++ b/types/matches.d.ts @@ -1,6 +1,6 @@ import {ARIARole} from 'aria-query' -export type MatcherFunction = (content: string, element: HTMLElement) => boolean +export type MatcherFunction = (content: string, element: Element) => boolean export type Matcher = MatcherFunction | {} // Get autocomplete for ARIARole union types, while still supporting another string @@ -22,7 +22,7 @@ export interface MatcherOptions { export type Match = ( textToMatch: string, - node: HTMLElement | null, + node: Element | null, matcher: Matcher, options?: MatcherOptions, ) => boolean diff --git a/types/queries.d.ts b/types/queries.d.ts index 8418d99c..b100fafd 100644 --- a/types/queries.d.ts +++ b/types/queries.d.ts @@ -3,68 +3,68 @@ import {SelectorMatcherOptions} from './query-helpers' import {waitForOptions} from './wait-for' export type QueryByBoundAttribute = ( - container: HTMLElement, + container: Element, id: Matcher, options?: MatcherOptions, -) => HTMLElement | null +) => Element | null export type AllByBoundAttribute = ( - container: HTMLElement, + container: Element, id: Matcher, options?: MatcherOptions, -) => HTMLElement[] +) => Element[] export type FindAllByBoundAttribute = ( - container: HTMLElement, + container: Element, id: Matcher, options?: MatcherOptions, waitForElementOptions?: waitForOptions, -) => Promise +) => Promise export type GetByBoundAttribute = ( - container: HTMLElement, + container: Element, id: Matcher, options?: MatcherOptions, -) => HTMLElement +) => Element export type FindByBoundAttribute = ( - container: HTMLElement, + container: Element, id: Matcher, options?: MatcherOptions, waitForElementOptions?: waitForOptions, -) => Promise +) => Promise export type QueryByText = ( - container: HTMLElement, + container: Element, id: Matcher, options?: SelectorMatcherOptions, -) => HTMLElement | null +) => Element | null export type AllByText = ( - container: HTMLElement, + container: Element, id: Matcher, options?: SelectorMatcherOptions, -) => HTMLElement[] +) => Element[] export type FindAllByText = ( - container: HTMLElement, + container: Element, id: Matcher, options?: SelectorMatcherOptions, waitForElementOptions?: waitForOptions, -) => Promise +) => Promise export type GetByText = ( - container: HTMLElement, + container: Element, id: Matcher, options?: SelectorMatcherOptions, -) => HTMLElement +) => Element export type FindByText = ( - container: HTMLElement, + container: Element, id: Matcher, options?: SelectorMatcherOptions, waitForElementOptions?: waitForOptions, -) => Promise +) => Promise export interface ByRoleOptions extends MatcherOptions { /** @@ -109,36 +109,36 @@ export interface ByRoleOptions extends MatcherOptions { } export type AllByRole = ( - container: HTMLElement, + container: Element, role: ByRoleMatcher, options?: ByRoleOptions, -) => HTMLElement[] +) => Element[] export type GetByRole = ( - container: HTMLElement, + container: Element, role: ByRoleMatcher, options?: ByRoleOptions, -) => HTMLElement +) => Element export type QueryByRole = ( - container: HTMLElement, + container: Element, role: ByRoleMatcher, options?: ByRoleOptions, -) => HTMLElement | null +) => Element | null export type FindByRole = ( - container: HTMLElement, + container: Element, role: ByRoleMatcher, options?: ByRoleOptions, waitForElementOptions?: waitForOptions, -) => Promise +) => Promise export type FindAllByRole = ( - container: HTMLElement, + container: Element, role: ByRoleMatcher, options?: ByRoleOptions, waitForElementOptions?: waitForOptions, -) => Promise +) => Promise export const getByLabelText: GetByText export const getAllByLabelText: AllByText diff --git a/types/query-helpers.d.ts b/types/query-helpers.d.ts index 26c80f19..b8562c7f 100644 --- a/types/query-helpers.d.ts +++ b/types/query-helpers.d.ts @@ -7,45 +7,45 @@ export interface SelectorMatcherOptions extends MatcherOptions { export type QueryByAttribute = ( attribute: string, - container: HTMLElement, + container: Element, id: Matcher, options?: MatcherOptions, -) => HTMLElement | null +) => Element | null export type AllByAttribute = ( attribute: string, - container: HTMLElement, + container: Element, id: Matcher, options?: MatcherOptions, -) => HTMLElement[] +) => Element[] export const queryByAttribute: QueryByAttribute export const queryAllByAttribute: AllByAttribute -export function getElementError(message: string, container: HTMLElement): Error +export function getElementError(message: string, container: Element): Error /** * query methods have a common call signature. Only the return type differs. */ export type QueryMethod = ( - container: HTMLElement, + container: Element, ...args: Arguments ) => Return export type QueryBy = QueryMethod< Arguments, - HTMLElement | null + Element | null > export type GetAllBy = QueryMethod< Arguments, - HTMLElement[] + Element[] > export type FindAllBy = QueryMethod< [Arguments[0], Arguments[1]?, waitForOptions?], - Promise + Promise > -export type GetBy = QueryMethod +export type GetBy = QueryMethod export type FindBy = QueryMethod< [Arguments[0], Arguments[1]?, waitForOptions?], - Promise + Promise > export type BuiltQueryMethods = [ @@ -57,6 +57,6 @@ export type BuiltQueryMethods = [ ] export function buildQueries( queryByAll: GetAllBy, - getMultipleError: (container: HTMLElement, ...args: Arguments) => string, - getMissingError: (container: HTMLElement, ...args: Arguments) => string, + getMultipleError: (container: Element, ...args: Arguments) => string, + getMissingError: (container: Element, ...args: Arguments) => string, ): BuiltQueryMethods diff --git a/types/role-helpers.d.ts b/types/role-helpers.d.ts index 4aaf54b0..345f8e55 100644 --- a/types/role-helpers.d.ts +++ b/types/role-helpers.d.ts @@ -1,7 +1,7 @@ -export function logRoles(container: HTMLElement): string +export function logRoles(container: Element): string export function getRoles( - container: HTMLElement, -): {[index: string]: HTMLElement[]} + container: Element, +): {[index: string]: Element[]} /** * https://testing-library.com/docs/dom-testing-library/api-helpers#isinaccessible */ diff --git a/types/suggestions.d.ts b/types/suggestions.d.ts index c2743641..dfaacfe2 100644 --- a/types/suggestions.d.ts +++ b/types/suggestions.d.ts @@ -40,7 +40,7 @@ export type Method = | 'testid' export function getSuggestedQuery( - element: HTMLElement, + element: Element, variant?: Variant, method?: Method, ): Suggestion | undefined diff --git a/types/wait-for.d.ts b/types/wait-for.d.ts index f5850dac..97330e1c 100644 --- a/types/wait-for.d.ts +++ b/types/wait-for.d.ts @@ -1,5 +1,5 @@ export interface waitForOptions { - container?: HTMLElement + container?: Element timeout?: number interval?: number onTimeout?: (error: Error) => Error