mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
[testing-library__dom] Fix async bound queries (#41237)
* Update get-queries-for-element.d.ts Fixes bound query types for queries with waitForElementOptions * Add tests * Adding self to package header
This commit is contained in:
committed by
Ryan Cavanaugh
parent
ca73215c06
commit
ba283aae0d
@@ -8,6 +8,8 @@ export type BoundFunction<T> = T extends (
|
||||
options: infer Q,
|
||||
) => infer R
|
||||
? (text: P, options?: Q) => R
|
||||
: T extends (a1: any, text: infer P, options: infer Q, waitForElementOptions: infer W) => infer R
|
||||
? (text: P, options?: Q, waitForElementOptions?: W) => R
|
||||
: T extends (a1: any, text: infer P, options: infer Q) => infer R
|
||||
? (text: P, options?: Q) => R
|
||||
: never;
|
||||
|
||||
1
types/testing-library__dom/index.d.ts
vendored
1
types/testing-library__dom/index.d.ts
vendored
@@ -6,6 +6,7 @@
|
||||
// Weyert de Boer <https://github.com/weyert>
|
||||
// Ronald Rey <https://github.com/reyronald>
|
||||
// Justin Hall <https://github.com/wKovacs64>
|
||||
// Wesley Tsai <https://github.com/wezleytsai>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.0
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { queries, screen, isInaccessible } from '@testing-library/dom';
|
||||
|
||||
const { getByText, queryByText, findByText, getAllByText, queryAllByText, findAllByText, queryByRole } = queries;
|
||||
const { getByText, queryByText, findByText, getAllByText, queryAllByText, findAllByText, queryByRole, findByRole } = queries;
|
||||
|
||||
async function testQueries() {
|
||||
// element queries
|
||||
@@ -8,20 +8,24 @@ async function testQueries() {
|
||||
getByText(element, 'foo');
|
||||
queryByText(element, 'foo');
|
||||
await findByText(element, 'foo');
|
||||
await findByText(element, 'foo', undefined, { timeout: 10 });
|
||||
getAllByText(element, 'bar');
|
||||
queryAllByText(element, 'bar');
|
||||
await findAllByText(element, 'bar');
|
||||
await findAllByText(element, 'bar', undefined, { timeout: 10 });
|
||||
|
||||
// screen queries
|
||||
screen.getByText('foo');
|
||||
screen.queryByText('foo');
|
||||
await screen.findByText('foo');
|
||||
await screen.findByText('foo', undefined, { timeout: 10 });
|
||||
screen.getAllByText('bar');
|
||||
screen.queryAllByText('bar');
|
||||
await screen.findAllByText('bar');
|
||||
await screen.findAllByText('bar', undefined, { timeout: 10 });
|
||||
}
|
||||
|
||||
function testByRole() {
|
||||
async function testByRole() {
|
||||
const element = document.createElement('button');
|
||||
element.setAttribute('aria-hidden', 'true');
|
||||
|
||||
@@ -30,6 +34,9 @@ function testByRole() {
|
||||
|
||||
console.assert(screen.queryByRole('button') === null);
|
||||
console.assert(screen.queryByRole('button', { hidden: true }) !== null);
|
||||
|
||||
console.assert(await findByRole(element, 'button', undefined, { timeout: 10 }) === null);
|
||||
console.assert(await findByRole(element, 'button', { hidden: true }, { timeout: 10 }) !== null);
|
||||
}
|
||||
|
||||
function testA11yHelper() {
|
||||
|
||||
Reference in New Issue
Block a user