MCPcopy
hub / github.com/facebook/react / findAllNodes

Function findAllNodes

packages/react-reconciler/src/ReactTestSelectors.js:306–343  ·  view source on GitHub ↗
(
  hostRoot: Instance,
  selectors: Array<Selector>,
)

Source from the content-addressed store, hash-verified

304}
305
306export function findAllNodes(
307 hostRoot: Instance,
308 selectors: Array<Selector>,
309): Array<Instance> {
310 if (!supportsTestSelectors) {
311 throw new Error('Test selector API is not supported by this renderer.');
312 }
313
314 const root = findFiberRootForHostRoot(hostRoot);
315 const matchingFibers = findPaths(root, selectors);
316
317 const instanceRoots: Array<Instance> = [];
318
319 const stack = Array.from(matchingFibers);
320 let index = 0;
321 while (index < stack.length) {
322 const node = ((stack[index++]: any): Fiber);
323 const tag = node.tag;
324 if (
325 tag === HostComponent ||
326 tag === HostHoistable ||
327 tag === HostSingleton
328 ) {
329 if (isHiddenSubtree(node)) {
330 continue;
331 }
332 instanceRoots.push(node.stateNode);
333 } else {
334 let child = node.child;
335 while (child !== null) {
336 stack.push(child);
337 child = child.sibling;
338 }
339 }
340 }
341
342 return instanceRoots;
343}
344
345export function getFindAllNodesFailureDescription(
346 hostRoot: Instance,

Callers 12

addItemFunction · 0.85
clickButtonFunction · 0.85
getElementCountFunction · 0.85
selectElementFunction · 0.85
components.test.jsFile · 0.85
getSnapshotSelectorTextFunction · 0.85
profiler.test.jsFile · 0.85
findBoundingRectsFunction · 0.85
observeVisibleRectsFunction · 0.85
commitHookFunction · 0.85

Calls 4

isHiddenSubtreeFunction · 0.90
findFiberRootForHostRootFunction · 0.85
findPathsFunction · 0.85
pushMethod · 0.65

Tested by 6

addItemFunction · 0.68
clickButtonFunction · 0.68
getElementCountFunction · 0.68
selectElementFunction · 0.68
getSnapshotSelectorTextFunction · 0.68