MCPcopy
hub / github.com/testing-library/dom-testing-library / queryAllByText

Function queryAllByText

src/queries/text.ts:18–46  ·  view source on GitHub ↗
(
  container,
  text,
  {
    selector = '*',
    exact = true,
    collapseWhitespace,
    trim,
    ignore = getConfig().defaultIgnore,
    normalizer,
  } = {},
)

Source from the content-addressed store, hash-verified

16} from './all-utils'
17
18const queryAllByText: AllByText = (
19 container,
20 text,
21 {
22 selector = '*',
23 exact = true,
24 collapseWhitespace,
25 trim,
26 ignore = getConfig().defaultIgnore,
27 normalizer,
28 } = {},
29) => {
30 checkContainerType(container)
31 const matcher = exact ? matches : fuzzyMatches
32 const matchNormalizer = makeNormalizer({collapseWhitespace, trim, normalizer})
33 let baseArray: HTMLElement[] = []
34 if (typeof container.matches === 'function' && container.matches(selector)) {
35 baseArray = [container]
36 }
37 return (
38 [
39 ...baseArray,
40 ...Array.from(container.querySelectorAll<HTMLElement>(selector)),
41 ]
42 // TODO: `matches` according lib.dom.d.ts can get only `string` but according our code it can handle also boolean :)
43 .filter(node => !ignore || !node.matches(ignore as string))
44 .filter(node => matcher(getNodeText(node), node, text, matchNormalizer))
45 )
46}
47
48const getMultipleError: GetErrorFunction<[unknown]> = (c, text) =>
49 `Found multiple elements with the text: ${text}`

Callers 3

testQueriesFunction · 0.85
element-queries.jsFile · 0.85
text-matchers.jsFile · 0.85

Calls 4

checkContainerTypeFunction · 0.90
getConfigFunction · 0.85
makeNormalizerFunction · 0.85
getNodeTextFunction · 0.85

Tested by 1

testQueriesFunction · 0.68