| 16 | } from './all-utils' |
| 17 | |
| 18 | const 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 | |
| 48 | const getMultipleError: GetErrorFunction<[unknown]> = (c, text) => |
| 49 | `Found multiple elements with the text: ${text}` |