Simple and complete DOM testing utilities that encourage good testing +practices.
+ +[**Read the docs**](https://testing-library.com/dom) | +[Edit the docs](https://github.com/testing-library/testing-library-docs) + += Q extends typeof queries + ? { + getByLabelText( + ...args: Parameters >> + ): ReturnType > + getAllByLabelText ( + ...args: Parameters >> + ): ReturnType > + queryByLabelText ( + ...args: Parameters >> + ): ReturnType > + queryAllByLabelText ( + ...args: Parameters >> + ): ReturnType > + findByLabelText ( + ...args: Parameters >> + ): ReturnType > + findAllByLabelText ( + ...args: Parameters >> + ): ReturnType > + getByPlaceholderText ( + ...args: Parameters >> + ): ReturnType > + getAllByPlaceholderText ( + ...args: Parameters >> + ): ReturnType > + queryByPlaceholderText ( + ...args: Parameters >> + ): ReturnType > + queryAllByPlaceholderText ( + ...args: Parameters >> + ): ReturnType > + findByPlaceholderText ( + ...args: Parameters >> + ): ReturnType > + findAllByPlaceholderText ( + ...args: Parameters >> + ): ReturnType > + getByText ( + ...args: Parameters >> + ): ReturnType > + getAllByText ( + ...args: Parameters >> + ): ReturnType > + queryByText ( + ...args: Parameters >> + ): ReturnType > + queryAllByText ( + ...args: Parameters >> + ): ReturnType > + findByText ( + ...args: Parameters >> + ): ReturnType > + findAllByText ( + ...args: Parameters >> + ): ReturnType > + getByAltText ( + ...args: Parameters >> + ): ReturnType > + getAllByAltText ( + ...args: Parameters >> + ): ReturnType > + queryByAltText ( + ...args: Parameters >> + ): ReturnType > + queryAllByAltText ( + ...args: Parameters >> + ): ReturnType > + findByAltText ( + ...args: Parameters >> + ): ReturnType > + findAllByAltText ( + ...args: Parameters >> + ): ReturnType > + getByTitle ( + ...args: Parameters >> + ): ReturnType > + getAllByTitle ( + ...args: Parameters >> + ): ReturnType > + queryByTitle ( + ...args: Parameters >> + ): ReturnType > + queryAllByTitle ( + ...args: Parameters >> + ): ReturnType > + findByTitle ( + ...args: Parameters >> + ): ReturnType > + findAllByTitle ( + ...args: Parameters >> + ): ReturnType > + getByDisplayValue ( + ...args: Parameters >> + ): ReturnType > + getAllByDisplayValue ( + ...args: Parameters >> + ): ReturnType > + queryByDisplayValue ( + ...args: Parameters >> + ): ReturnType > + queryAllByDisplayValue ( + ...args: Parameters >> + ): ReturnType > + findByDisplayValue ( + ...args: Parameters >> + ): ReturnType > + findAllByDisplayValue ( + ...args: Parameters >> + ): ReturnType > + getByRole ( + ...args: Parameters >> + ): ReturnType > + getAllByRole ( + ...args: Parameters >> + ): ReturnType > + queryByRole ( + ...args: Parameters >> + ): ReturnType > + queryAllByRole ( + ...args: Parameters >> + ): ReturnType > + findByRole ( + ...args: Parameters >> + ): ReturnType > + findAllByRole ( + ...args: Parameters >> + ): ReturnType > + getByTestId ( + ...args: Parameters >> + ): ReturnType > + getAllByTestId ( + ...args: Parameters >> + ): ReturnType > + queryByTestId ( + ...args: Parameters >> + ): ReturnType > + queryAllByTestId ( + ...args: Parameters >> + ): ReturnType > + findByTestId ( + ...args: Parameters >> + ): ReturnType > + findAllByTestId ( + ...args: Parameters >> + ): ReturnType > + } & { + [P in keyof Q]: BoundFunction + } + : { + [P in keyof Q]: BoundFunction+ } + +export type Query = ( + container: HTMLElement, + ...args: any[] +) => + | Error + | HTMLElement + | HTMLElement[] + | Promise+ | Promise + | null + +export interface Queries { + [T: string]: Query +} + +export function getQueriesForElement< + QueriesToBind extends Queries = typeof queries, + // Extra type parameter required for reassignment. + T extends QueriesToBind = QueriesToBind, +>(element: HTMLElement, queriesToBind?: T): BoundFunctions diff --git a/node_modules/@testing-library/dom/types/index.d.ts b/node_modules/@testing-library/dom/types/index.d.ts new file mode 100644 index 000000000000..b5dcfbc2833c --- /dev/null +++ b/node_modules/@testing-library/dom/types/index.d.ts @@ -0,0 +1,22 @@ +// TypeScript Version: 3.8 + +import {getQueriesForElement} from './get-queries-for-element' +import * as queries from './queries' +import * as queryHelpers from './query-helpers' + +declare const within: typeof getQueriesForElement +export {queries, queryHelpers, within} + +export * from './queries' +export * from './query-helpers' +export * from './screen' +export * from './wait-for' +export * from './wait-for-element-to-be-removed' +export * from './matches' +export * from './get-node-text' +export * from './events' +export * from './get-queries-for-element' +export * from './pretty-dom' +export * from './role-helpers' +export * from './config' +export * from './suggestions' diff --git a/node_modules/@testing-library/dom/types/matches.d.ts b/node_modules/@testing-library/dom/types/matches.d.ts new file mode 100644 index 000000000000..9df516803758 --- /dev/null +++ b/node_modules/@testing-library/dom/types/matches.d.ts @@ -0,0 +1,46 @@ +import {ARIARole} from 'aria-query' + +export type MatcherFunction = ( + content: string, + element: Element | null, +) => boolean +export type Matcher = MatcherFunction | RegExp | number | string + +// Get autocomplete for ARIARole union types, while still supporting another string +// Ref: https://github.com/microsoft/TypeScript/issues/29729#issuecomment-567871939 +export type ByRoleMatcher = ARIARole | (string & {}) + +export type NormalizerFn = (text: string) => string + +export interface NormalizerOptions extends DefaultNormalizerOptions { + normalizer?: NormalizerFn +} + +export interface MatcherOptions { + exact?: boolean + /** Use normalizer with getDefaultNormalizer instead */ + trim?: boolean + /** Use normalizer with getDefaultNormalizer instead */ + collapseWhitespace?: boolean + normalizer?: NormalizerFn + /** suppress suggestions for a specific query */ + suggest?: boolean +} + +export type Match = ( + textToMatch: string, + node: HTMLElement | null, + matcher: Matcher, + options?: MatcherOptions, +) => boolean + +export interface DefaultNormalizerOptions { + trim?: boolean + collapseWhitespace?: boolean +} + +export function getDefaultNormalizer( + options?: DefaultNormalizerOptions, +): NormalizerFn + +// N.B. Don't expose fuzzyMatches + matches here: they're not public API diff --git a/node_modules/@testing-library/dom/types/pretty-dom.d.ts b/node_modules/@testing-library/dom/types/pretty-dom.d.ts new file mode 100644 index 000000000000..6b413b3bb09e --- /dev/null +++ b/node_modules/@testing-library/dom/types/pretty-dom.d.ts @@ -0,0 +1,21 @@ +import * as prettyFormat from 'pretty-format' + +export interface PrettyDOMOptions extends prettyFormat.OptionsReceived { + /** + * Given a `Node` return `false` if you wish to ignore that node in the output. + * By default, ignores ``, `` and comment nodes. + */ + filterNode?: (node: Node) => boolean +} + +export function prettyDOM( + dom?: Element | HTMLDocument, + maxLength?: number, + options?: PrettyDOMOptions, +): string | false +export function logDOM( + dom?: Element | HTMLDocument, + maxLength?: number, + options?: PrettyDOMOptions, +): void +export {prettyFormat} diff --git a/node_modules/@testing-library/dom/types/queries.d.ts b/node_modules/@testing-library/dom/types/queries.d.ts new file mode 100644 index 000000000000..c6ce90546597 --- /dev/null +++ b/node_modules/@testing-library/dom/types/queries.d.ts @@ -0,0 +1,315 @@ +import {ByRoleMatcher, Matcher, MatcherOptions} from './matches' +import {SelectorMatcherOptions} from './query-helpers' +import {waitForOptions} from './wait-for' + +export type QueryByBoundAttribute = ( + container: HTMLElement, + id: Matcher, + options?: MatcherOptions, +) => T | null + +export type AllByBoundAttribute = ( + container: HTMLElement, + id: Matcher, + options?: MatcherOptions, +) => T[] + +export type FindAllByBoundAttribute = ( + container: HTMLElement, + id: Matcher, + options?: MatcherOptions, + waitForElementOptions?: waitForOptions, +) => Promise + +export type GetByBoundAttribute = ( + container: HTMLElement, + id: Matcher, + options?: MatcherOptions, +) => T + +export type FindByBoundAttribute = ( + container: HTMLElement, + id: Matcher, + options?: MatcherOptions, + waitForElementOptions?: waitForOptions, +) => Promise + +export type QueryByText = ( + container: HTMLElement, + id: Matcher, + options?: SelectorMatcherOptions, +) => T | null + +export type AllByText = ( + container: HTMLElement, + id: Matcher, + options?: SelectorMatcherOptions, +) => T[] + +export type FindAllByText = ( + container: HTMLElement, + id: Matcher, + options?: SelectorMatcherOptions, + waitForElementOptions?: waitForOptions, +) => Promise + +export type GetByText = ( + container: HTMLElement, + id: Matcher, + options?: SelectorMatcherOptions, +) => T + +export type FindByText = ( + container: HTMLElement, + id: Matcher, + options?: SelectorMatcherOptions, + waitForElementOptions?: waitForOptions, +) => Promise + +export interface ByRoleOptions { + /** suppress suggestions for a specific query */ + suggest?: boolean + /** + * If true includes elements in the query set that are usually excluded from + * the accessibility tree. `role="none"` or `role="presentation"` are included + * in either case. + */ + hidden?: boolean + /** + * If true only includes elements in the query set that are marked as + * selected in the accessibility tree, i.e., `aria-selected="true"` + */ + selected?: boolean + /** + * If true only includes elements in the query set that are marked as + * busy in the accessibility tree, i.e., `aria-busy="true"` + */ + busy?: boolean + /** + * If true only includes elements in the query set that are marked as + * checked in the accessibility tree, i.e., `aria-checked="true"` + */ + checked?: boolean + /** + * If true only includes elements in the query set that are marked as + * pressed in the accessibility tree, i.e., `aria-pressed="true"` + */ + pressed?: boolean + /** + * Filters elements by their `aria-current` state. `true` and `false` match `aria-current="true"` and `aria-current="false"` (as well as a missing `aria-current` attribute) respectively. + */ + current?: boolean | string + /** + * If true only includes elements in the query set that are marked as + * expanded in the accessibility tree, i.e., `aria-expanded="true"` + */ + expanded?: boolean + /** + * Includes elements with the `"heading"` role matching the indicated level, + * either by the semantic HTML heading elements ` -
` or matching + * the `aria-level` attribute. + */ + level?: number + value?: { + now?: number + min?: number + max?: number + text?: Matcher + } + /** + * Includes every role used in the `role` attribute + * For example *ByRole('progressbar', {queryFallbacks: true})` will find
`. + */ + queryFallbacks?: boolean + /** + * Only considers elements with the specified accessible name. + */ + name?: + | RegExp + | string + | ((accessibleName: string, element: Element) => boolean) + /** + * Only considers elements with the specified accessible description. + */ + description?: + | RegExp + | string + | ((accessibleDescription: string, element: Element) => boolean) +} + +export type AllByRole= ( + container: HTMLElement, + role: ByRoleMatcher, + options?: ByRoleOptions, +) => T[] + +export type GetByRole = ( + container: HTMLElement, + role: ByRoleMatcher, + options?: ByRoleOptions, +) => T + +export type QueryByRole = ( + container: HTMLElement, + role: ByRoleMatcher, + options?: ByRoleOptions, +) => T | null + +export type FindByRole = ( + container: HTMLElement, + role: ByRoleMatcher, + options?: ByRoleOptions, + waitForElementOptions?: waitForOptions, +) => Promise + +export type FindAllByRole = ( + container: HTMLElement, + role: ByRoleMatcher, + options?: ByRoleOptions, + waitForElementOptions?: waitForOptions, +) => Promise + +export function getByLabelText ( + ...args: Parameters > +): ReturnType > +export function getAllByLabelText ( + ...args: Parameters > +): ReturnType > +export function queryByLabelText ( + ...args: Parameters > +): ReturnType > +export function queryAllByLabelText ( + ...args: Parameters > +): ReturnType > +export function findByLabelText ( + ...args: Parameters > +): ReturnType > +export function findAllByLabelText ( + ...args: Parameters > +): ReturnType > +export function getByPlaceholderText ( + ...args: Parameters > +): ReturnType > +export function getAllByPlaceholderText ( + ...args: Parameters > +): ReturnType > +export function queryByPlaceholderText ( + ...args: Parameters > +): ReturnType > +export function queryAllByPlaceholderText ( + ...args: Parameters > +): ReturnType > +export function findByPlaceholderText ( + ...args: Parameters > +): ReturnType > +export function findAllByPlaceholderText ( + ...args: Parameters > +): ReturnType > +export function getByText ( + ...args: Parameters > +): ReturnType > +export function getAllByText ( + ...args: Parameters > +): ReturnType > +export function queryByText ( + ...args: Parameters > +): ReturnType > +export function queryAllByText ( + ...args: Parameters > +): ReturnType > +export function findByText ( + ...args: Parameters > +): ReturnType > +export function findAllByText ( + ...args: Parameters > +): ReturnType > +export function getByAltText ( + ...args: Parameters > +): ReturnType > +export function getAllByAltText ( + ...args: Parameters > +): ReturnType > +export function queryByAltText ( + ...args: Parameters > +): ReturnType > +export function queryAllByAltText