Skip to content

Commit 3cde22a

Browse files
author
Brian Vaughn
authored
Experimental test selector API (#18607)
Adds several new experimental APIs to aid with automated testing. Each of the methods below accepts an array of "selectors" that identifies a path (or paths) through a React tree. There are four basic selector types: * Component: Matches Fibers with the specified React component type * Role: Matches Host Instances matching the (explicit or implicit) accessibility role. * Test name: Matches Host Instances with a data-testname attribute. * Text: Matches Host Instances that directly contain the specified text. * There is also a special lookahead selector type that enables further matching within a path (without actually including the path in the result). This selector type was inspired by the :has() CSS pseudo-class. It enables e.g. matching a <section> that contained a specific header text, then finding a like button within that <section>. API * findAllNodes(): Finds all Host Instances (e.g. HTMLElement) within a host subtree that match the specified selector criteria. * getFindAllNodesFailureDescription(): Returns an error string describing the matched and unmatched portions of the selector query. * findBoundingRects(): For all React components within a host subtree that match the specified selector criteria, return a set of bounding boxes that covers the bounds of the nearest (shallowed) Host Instances within those trees. * observeVisibleRects(): For all React components within a host subtree that match the specified selector criteria, observe if it’s bounding rect is visible in the viewport and is not occluded. * focusWithin(): For all React components within a host subtree that match the specified selector criteria, set focus within the first focusable Host Instance (as if you started before this component in the tree and moved focus forwards one step).
1 parent c13a59c commit 3cde22a

19 files changed

+2466
-8
lines changed

packages/react-art/src/ReactARTHostConfig.js

+1
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ function applyTextProps(instance, props, prevProps = {}) {
244244
export * from 'react-reconciler/src/ReactFiberHostConfigWithNoPersistence';
245245
export * from 'react-reconciler/src/ReactFiberHostConfigWithNoHydration';
246246
export * from 'react-reconciler/src/ReactFiberHostConfigWithNoScopes';
247+
export * from 'react-reconciler/src/ReactFiberHostConfigWithNoTestSelectors';
247248

248249
export function appendInitialChild(parentInstance, child) {
249250
if (typeof child === 'string') {

0 commit comments

Comments
 (0)