[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:
Wesley Tsai
2020-01-03 01:47:11 +08:00
committed by Ryan Cavanaugh
parent ca73215c06
commit ba283aae0d
3 changed files with 12 additions and 2 deletions

View File

@@ -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;

View File

@@ -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

View File

@@ -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() {