From ba283aae0d480f5379ef075f6a1129dd99eb458c Mon Sep 17 00:00:00 2001 From: Wesley Tsai Date: Fri, 3 Jan 2020 01:47:11 +0800 Subject: [PATCH] [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 --- .../testing-library__dom/get-queries-for-element.d.ts | 2 ++ types/testing-library__dom/index.d.ts | 1 + .../testing-library__dom-tests.ts | 11 +++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/types/testing-library__dom/get-queries-for-element.d.ts b/types/testing-library__dom/get-queries-for-element.d.ts index 5441075814..90e5626d55 100644 --- a/types/testing-library__dom/get-queries-for-element.d.ts +++ b/types/testing-library__dom/get-queries-for-element.d.ts @@ -8,6 +8,8 @@ export type BoundFunction = 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; diff --git a/types/testing-library__dom/index.d.ts b/types/testing-library__dom/index.d.ts index be4b06a2fd..0401e09175 100644 --- a/types/testing-library__dom/index.d.ts +++ b/types/testing-library__dom/index.d.ts @@ -6,6 +6,7 @@ // Weyert de Boer // Ronald Rey // Justin Hall +// Wesley Tsai // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.0 diff --git a/types/testing-library__dom/testing-library__dom-tests.ts b/types/testing-library__dom/testing-library__dom-tests.ts index deca847b79..8f26bc884d 100644 --- a/types/testing-library__dom/testing-library__dom-tests.ts +++ b/types/testing-library__dom/testing-library__dom-tests.ts @@ -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() {