feat(testing-library__dom): Add byRole#hidden (#38560)

* feat(testing-library__dom): Add byRole#hidden

* Update version
This commit is contained in:
Sebastian Silbermann 2019-09-25 22:46:58 +02:00 committed by Michael Crane
parent fe0910342b
commit c1dd9cf3e1
3 changed files with 46 additions and 8 deletions

View File

@ -1,4 +1,4 @@
// Type definitions for @testing-library/dom 6.0
// Type definitions for @testing-library/dom 6.4
// Project: https://github.com/testing-library/dom-testing-library
// Definitions by: Alex Krolick <https://github.com/alexkrolick>
// Kent C Dodds <https://github.com/kentcdodds>

View File

@ -46,6 +46,36 @@ export type FindByText = (
waitForElementOptions?: WaitForElementOptions,
) => Promise<HTMLElement>;
export interface ByRoleOptions extends MatcherOptions {
/**
* 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.
* @default false
*/
hidden?: boolean;
}
export type AllByRole = (container: HTMLElement, role: Matcher, options?: ByRoleOptions) => HTMLElement[];
export type GetByRole = (container: HTMLElement, role: Matcher, options?: ByRoleOptions) => HTMLElement;
export type QueryByRole = (container: HTMLElement, role: Matcher, options?: ByRoleOptions) => HTMLElement | null;
export type FindByRole = (
container: HTMLElement,
role: Matcher,
options?: ByRoleOptions,
waitForElementOptions?: WaitForElementOptions,
) => Promise<HTMLElement>;
export type FindAllByRole = (
container: HTMLElement,
role: Matcher,
options?: ByRoleOptions,
waitForElementOptions?: WaitForElementOptions,
) => Promise<HTMLElement[]>;
export const getByLabelText: GetByText;
export const getAllByLabelText: AllByText;
export const queryByLabelText: QueryByText;
@ -82,12 +112,12 @@ export const queryByDisplayValue: QueryByBoundAttribute;
export const queryAllByDisplayValue: AllByBoundAttribute;
export const findByDisplayValue: FindByBoundAttribute;
export const findAllByDisplayValue: FindAllByBoundAttribute;
export const getByRole: GetByBoundAttribute;
export const getAllByRole: AllByBoundAttribute;
export const queryByRole: QueryByBoundAttribute;
export const queryAllByRole: AllByBoundAttribute;
export const findByRole: FindByBoundAttribute;
export const findAllByRole: FindAllByBoundAttribute;
export const getByRole: GetByRole;
export const getAllByRole: AllByRole;
export const queryByRole: QueryByRole;
export const queryAllByRole: AllByRole;
export const findByRole: FindByRole;
export const findAllByRole: FindAllByRole;
export const getByTestId: GetByBoundAttribute;
export const getAllByTestId: AllByBoundAttribute;
export const queryByTestId: QueryByBoundAttribute;

View File

@ -1,6 +1,6 @@
import { queries } from '@testing-library/dom';
const { getByText, queryByText, findByText, getAllByText, queryAllByText, findAllByText } = queries;
const { getByText, queryByText, findByText, getAllByText, queryAllByText, findAllByText, queryByRole } = queries;
async function testQueries() {
const element = document.createElement('div');
@ -11,3 +11,11 @@ async function testQueries() {
queryAllByText(element, 'bar');
await findAllByText(element, 'bar');
}
function testByRole() {
const element = document.createElement('button');
element.setAttribute('aria-hidden', 'true');
console.assert(queryByRole(element, 'button') === null);
console.assert(queryByRole(element, 'button', { hidden: true }) !== null);
}