|
1 | 1 | import {fuzzyMatches, matches} from './matches' |
2 | 2 | import {getNodeText} from './get-node-text' |
3 | | -import {prettyDOM} from './pretty-dom' |
4 | | - |
5 | | -function debugDOM(htmlElement) { |
6 | | - const limit = process.env.DEBUG_PRINT_LIMIT || 7000 |
7 | | - const inNode = typeof process !== 'undefined' && process.versions !== undefined && process.versions.node !== undefined |
8 | | - const inCypress = typeof window !== 'undefined' && window.Cypress |
9 | | - /* istanbul ignore else */ |
10 | | - if (inCypress) { |
11 | | - return '' |
12 | | - } else if (inNode) { |
13 | | - return prettyDOM(htmlElement, limit) |
14 | | - } else { |
15 | | - return prettyDOM(htmlElement, limit, {highlight: false}) |
16 | | - } |
17 | | -} |
18 | | - |
19 | | -function getElementError(message, container) { |
20 | | - return new Error([message, debugDOM(container)].filter(Boolean).join('\n\n')) |
21 | | -} |
| 3 | +import { |
| 4 | + getElementError, |
| 5 | + firstResultOrNull, |
| 6 | + queryAllByAttribute, |
| 7 | + queryByAttribute, |
| 8 | +} from './query-helpers' |
22 | 9 |
|
23 | 10 | // Here are the queries for the library. |
24 | 11 | // The queries here should only be things that are accessible to both users who are using a screen reader |
25 | 12 | // and those who are not using a screen reader (with the exception of the data-testid attribute query). |
26 | 13 |
|
27 | | -function firstResultOrNull(queryFunction, ...args) { |
28 | | - const result = queryFunction(...args) |
29 | | - if (result.length === 0) return null |
30 | | - return result[0] |
31 | | -} |
32 | | - |
33 | 14 | function queryAllLabelsByText( |
34 | 15 | container, |
35 | 16 | text, |
@@ -101,27 +82,6 @@ function queryByText(...args) { |
101 | 82 | return firstResultOrNull(queryAllByText, ...args) |
102 | 83 | } |
103 | 84 |
|
104 | | -// this is just a utility and not an exposed query. |
105 | | -// There are no plans to expose this. |
106 | | -function queryAllByAttribute( |
107 | | - attribute, |
108 | | - container, |
109 | | - text, |
110 | | - {exact = true, collapseWhitespace = true, trim = true} = {}, |
111 | | -) { |
112 | | - const matcher = exact ? matches : fuzzyMatches |
113 | | - const matchOpts = {collapseWhitespace, trim} |
114 | | - return Array.from(container.querySelectorAll(`[${attribute}]`)).filter(node => |
115 | | - matcher(node.getAttribute(attribute), node, text, matchOpts), |
116 | | - ) |
117 | | -} |
118 | | - |
119 | | -// this is just a utility and not an exposed query. |
120 | | -// There are no plans to expose this. |
121 | | -function queryByAttribute(...args) { |
122 | | - return firstResultOrNull(queryAllByAttribute, ...args) |
123 | | -} |
124 | | - |
125 | 85 | const queryByPlaceholderText = queryByAttribute.bind(null, 'placeholder') |
126 | 86 | const queryAllByPlaceholderText = queryAllByAttribute.bind(null, 'placeholder') |
127 | 87 | const queryByTestId = queryByAttribute.bind(null, 'data-testid') |
|
0 commit comments