feat(testing-library__dom): add screen export (#41052)

This commit is contained in:
Justin Hall
2019-12-16 04:05:24 -07:00
committed by Orta
parent 288692b272
commit 260e3f2f9f
3 changed files with 22 additions and 2 deletions

View File

@@ -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 <https://github.com/alexkrolick>
// Kent C Dodds <https://github.com/kentcdodds>
// Sebastian Silbermann <https://github.com/eps1lon>
// Weyert de Boer <https://github.com/weyert>
// Ronald Rey <https://github.com/reyronald>
// Justin Hall <https://github.com/wKovacs64>
// 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';

View File

@@ -0,0 +1,6 @@
import { BoundFunctions, Queries } from './get-queries-for-element';
import * as queries from './queries';
export type Screen<Q extends Queries = typeof queries> = BoundFunctions<Q>;
export const screen: Screen;

View File

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