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

Function queryAllByDisplayValue

src/queries/display-value.ts:17–44  ·  view source on GitHub ↗
(
  container,
  value,
  {exact = true, collapseWhitespace, trim, normalizer} = {},
)

Source from the content-addressed store, hash-verified

15} from './all-utils'
16
17const queryAllByDisplayValue: AllByBoundAttribute = (
18 container,
19 value,
20 {exact = true, collapseWhitespace, trim, normalizer} = {},
21) => {
22 checkContainerType(container)
23 const matcher = exact ? matches : fuzzyMatches
24 const matchNormalizer = makeNormalizer({collapseWhitespace, trim, normalizer})
25 return Array.from(
26 container.querySelectorAll<HTMLElement>(`input,textarea,select`),
27 ).filter(node => {
28 if (node.tagName === 'SELECT') {
29 const selectedOptions = Array.from(
30 (node as HTMLSelectElement).options,
31 ).filter(option => option.selected)
32 return selectedOptions.some(optionNode =>
33 matcher(getNodeText(optionNode), optionNode, value, matchNormalizer),
34 )
35 } else {
36 return matcher(
37 (node as HTMLInputElement).value,
38 node,
39 value,
40 matchNormalizer,
41 )
42 }
43 })
44}
45
46const getMultipleError: GetErrorFunction<[unknown]> = (c, value) =>
47 `Found multiple elements with the display value: ${value}.`

Callers 1

element-queries.jsFile · 0.85

Calls 3

checkContainerTypeFunction · 0.90
makeNormalizerFunction · 0.85
getNodeTextFunction · 0.85

Tested by

no test coverage detected