mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-01 15:50:13 +00:00
feat(dom-testing-library): Types for 6.12 (#41951)
* feat(screen): Add debug * feat(fireEvent): Add popState * feat(ByRole): Add queryFallbacks * chore: Bump version
This commit is contained in:
committed by
GitHub
parent
3e1e03d0d4
commit
c5df2018a4
1
types/testing-library__dom/events.d.ts
vendored
1
types/testing-library__dom/events.d.ts
vendored
@@ -35,6 +35,7 @@ export type EventType =
|
||||
| 'mouseOut'
|
||||
| 'mouseOver'
|
||||
| 'mouseUp'
|
||||
| 'popState'
|
||||
| 'select'
|
||||
| 'touchCancel'
|
||||
| 'touchEnd'
|
||||
|
||||
2
types/testing-library__dom/index.d.ts
vendored
2
types/testing-library__dom/index.d.ts
vendored
@@ -1,4 +1,4 @@
|
||||
// Type definitions for @testing-library/dom 6.11
|
||||
// Type definitions for @testing-library/dom 6.12
|
||||
// Project: https://github.com/testing-library/dom-testing-library
|
||||
// Definitions by: Alex Krolick <https://github.com/alexkrolick>
|
||||
// Kent C Dodds <https://github.com/kentcdodds>
|
||||
|
||||
5
types/testing-library__dom/queries.d.ts
vendored
5
types/testing-library__dom/queries.d.ts
vendored
@@ -54,6 +54,11 @@ export interface ByRoleOptions extends MatcherOptions {
|
||||
* @default false
|
||||
*/
|
||||
hidden?: boolean;
|
||||
/**
|
||||
* Includes every role used in the `role` attribute
|
||||
* For example *ByRole('progressbar', {queryFallbacks: true})` will find <div role="meter progresbar">`.
|
||||
*/
|
||||
queryFallbacks?: boolean;
|
||||
}
|
||||
|
||||
export type AllByRole = (container: HTMLElement, role: Matcher, options?: ByRoleOptions) => HTMLElement[];
|
||||
|
||||
13
types/testing-library__dom/screen.d.ts
vendored
13
types/testing-library__dom/screen.d.ts
vendored
@@ -1,6 +1,17 @@
|
||||
import { BoundFunctions, Queries } from './get-queries-for-element';
|
||||
import * as queries from './queries';
|
||||
import { OptionsReceived } from 'pretty-format';
|
||||
|
||||
export type Screen<Q extends Queries = typeof queries> = BoundFunctions<Q>;
|
||||
export type Screen<Q extends Queries = typeof queries> = BoundFunctions<Q> & {
|
||||
/**
|
||||
* Convenience function for `pretty-dom` which also allows an array
|
||||
* of elements
|
||||
*/
|
||||
debug: (
|
||||
element: Element | HTMLDocument | Array<Element | HTMLDocument>,
|
||||
maxLength?: number,
|
||||
options?: OptionsReceived,
|
||||
) => void;
|
||||
};
|
||||
|
||||
export const screen: Screen;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { queries, screen, isInaccessible } from '@testing-library/dom';
|
||||
import { fireEvent, queries, screen, isInaccessible } from '@testing-library/dom';
|
||||
|
||||
const { getByText, queryByText, findByText, getAllByText, queryAllByText, findAllByText, queryByRole, findByRole } = queries;
|
||||
const { getByText, queryByText, findByText, getAllByText, queryAllByText, findAllByText, queryAllByRole, queryByRole, findByRole } = queries;
|
||||
|
||||
async function testQueries() {
|
||||
// element queries
|
||||
@@ -19,7 +19,7 @@ async function testQueries() {
|
||||
screen.queryByText('foo');
|
||||
await screen.findByText('foo');
|
||||
await screen.findByText('foo', undefined, { timeout: 10 });
|
||||
screen.getAllByText('bar');
|
||||
screen.debug(screen.getAllByText('bar'));
|
||||
screen.queryAllByText('bar');
|
||||
await screen.findAllByText('bar');
|
||||
await screen.findAllByText('bar', undefined, { timeout: 10 });
|
||||
@@ -37,9 +37,18 @@ async function testByRole() {
|
||||
|
||||
console.assert(await findByRole(element, 'button', undefined, { timeout: 10 }) === null);
|
||||
console.assert(await findByRole(element, 'button', { hidden: true }, { timeout: 10 }) !== null);
|
||||
|
||||
console.assert(queryAllByRole(document.body, 'progressbar', {queryFallbacks: true}).length === 1);
|
||||
}
|
||||
|
||||
function testA11yHelper() {
|
||||
const element = document.createElement('svg');
|
||||
console.assert(!isInaccessible(element));
|
||||
}
|
||||
|
||||
function eventTest() {
|
||||
fireEvent.popState(window, {
|
||||
location: 'http://www.example.com/?page=1',
|
||||
state: { page: 1 },
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user