diff --git a/types/testing-library__dom/index.d.ts b/types/testing-library__dom/index.d.ts index f98b69e36b..be4b06a2fd 100644 --- a/types/testing-library__dom/index.d.ts +++ b/types/testing-library__dom/index.d.ts @@ -1,10 +1,11 @@ -// Type definitions for @testing-library/dom 6.10 +// Type definitions for @testing-library/dom 6.11 // Project: https://github.com/testing-library/dom-testing-library // Definitions by: Alex Krolick // Kent C Dodds // Sebastian Silbermann // Weyert de Boer // Ronald Rey +// Justin Hall // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.0 @@ -17,6 +18,7 @@ export { queries, queryHelpers, within }; export * from './queries'; export * from './query-helpers'; +export * from './screen'; export * from './wait'; export * from './wait-for-dom-change'; export * from './wait-for-element'; diff --git a/types/testing-library__dom/screen.d.ts b/types/testing-library__dom/screen.d.ts new file mode 100644 index 0000000000..7a6ee6cc8c --- /dev/null +++ b/types/testing-library__dom/screen.d.ts @@ -0,0 +1,6 @@ +import { BoundFunctions, Queries } from './get-queries-for-element'; +import * as queries from './queries'; + +export type Screen = BoundFunctions; + +export const screen: Screen; diff --git a/types/testing-library__dom/testing-library__dom-tests.ts b/types/testing-library__dom/testing-library__dom-tests.ts index e6b74755b8..deca847b79 100644 --- a/types/testing-library__dom/testing-library__dom-tests.ts +++ b/types/testing-library__dom/testing-library__dom-tests.ts @@ -1,8 +1,9 @@ -import { queries, isInaccessible } from '@testing-library/dom'; +import { queries, screen, isInaccessible } from '@testing-library/dom'; const { getByText, queryByText, findByText, getAllByText, queryAllByText, findAllByText, queryByRole } = queries; async function testQueries() { + // element queries const element = document.createElement('div'); getByText(element, 'foo'); queryByText(element, 'foo'); @@ -10,6 +11,14 @@ async function testQueries() { getAllByText(element, 'bar'); queryAllByText(element, 'bar'); await findAllByText(element, 'bar'); + + // screen queries + screen.getByText('foo'); + screen.queryByText('foo'); + await screen.findByText('foo'); + screen.getAllByText('bar'); + screen.queryAllByText('bar'); + await screen.findAllByText('bar'); } function testByRole() { @@ -18,6 +27,9 @@ function testByRole() { console.assert(queryByRole(element, 'button') === null); console.assert(queryByRole(element, 'button', { hidden: true }) !== null); + + console.assert(screen.queryByRole('button') === null); + console.assert(screen.queryByRole('button', { hidden: true }) !== null); } function testA11yHelper() {