@ctrl/dom 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/aria/_chunks/roles-list-BXCvPLJT.cjs +4 -0
  2. package/dist/aria/_chunks/roles-list-rVVxaIPs.js +4 -0
  3. package/dist/aria/index.cjs +1 -232
  4. package/dist/aria/index.js +1 -198
  5. package/dist/aria/internal.cjs +1 -69
  6. package/dist/aria/internal.js +1 -30
  7. package/dist/cli/_chunks/report-z52LF7nA.js +12 -0
  8. package/dist/cli/_chunks/rolldown-runtime-H3fMLYWS.js +1 -0
  9. package/dist/cli/ctrl-dom.js +2 -181
  10. package/dist/cli/jest-reporter.js +2 -54
  11. package/dist/cli/vitest-reporter.js +2 -81
  12. package/dist/dom/_chunks/src-sZY6a2LC.js +49 -0
  13. package/dist/dom/index.js +1 -3
  14. package/dist/dom/internal.js +1 -434
  15. package/dist/dom/types/window/clock.d.ts +10 -2
  16. package/dist/jest-dom/_chunks/matchers-CGTk9GX9.cjs +31 -0
  17. package/dist/jest-dom/_chunks/matchers-Chf0yHoo.js +31 -0
  18. package/dist/jest-dom/index.cjs +1 -5
  19. package/dist/jest-dom/index.js +1 -6
  20. package/dist/jest-dom/jest-globals.cjs +1 -6
  21. package/dist/jest-dom/jest-globals.js +1 -7
  22. package/dist/jest-dom/matchers.cjs +1 -53
  23. package/dist/jest-dom/matchers.js +1 -3
  24. package/dist/jest-dom/vitest.cjs +1 -6
  25. package/dist/jest-dom/vitest.js +1 -7
  26. package/dist/react/_chunks/pure-CCeTO5Mk.js +1 -0
  27. package/dist/react/_chunks/pure-DQzwul4s.cjs +1 -0
  28. package/dist/react/dont-cleanup-after-each.cjs +1 -3
  29. package/dist/react/dont-cleanup-after-each.js +1 -4
  30. package/dist/react/index.cjs +1 -47
  31. package/dist/react/index.js +1 -35
  32. package/dist/react/pure.cjs +1 -17
  33. package/dist/react/pure.js +1 -5
  34. package/dist/register/index.js +1 -11
  35. package/dist/register/pure.js +1 -147
  36. package/dist/testing-library/_chunks/aria-snapshot-diff-80G4meO2.cjs +14 -0
  37. package/dist/testing-library/_chunks/aria-snapshot-diff-B1L8s_sM.js +14 -0
  38. package/dist/testing-library/agent.cjs +10 -720
  39. package/dist/testing-library/agent.js +10 -712
  40. package/dist/testing-library/index.cjs +19 -2459
  41. package/dist/testing-library/index.js +19 -2380
  42. package/dist/user-event/index.cjs +33 -3924
  43. package/dist/user-event/index.js +33 -3899
  44. package/dist/user-event/types/ctrl-dom.d.ts +1 -1
  45. package/dist/vitest-environment/_chunks/rolldown-runtime-BhWHdk3m.js +1 -0
  46. package/dist/vitest-environment/failure-snapshot.js +1 -42
  47. package/dist/vitest-environment/index.js +1 -185
  48. package/dist/vitest-environment/plugin.js +1 -90
  49. package/package.json +1 -1
  50. package/dist/aria/_chunks/roles-list-CYZF-l9K.js +0 -1503
  51. package/dist/aria/_chunks/roles-list-D4WCyRO_.cjs +0 -1754
  52. package/dist/cli/_chunks/report-DdncYfuJ.js +0 -93
  53. package/dist/dom/_chunks/src-Bwp4p8ko.js +0 -47601
  54. package/dist/jest-dom/_chunks/matchers-CDnnXUfG.js +0 -2211
  55. package/dist/jest-dom/_chunks/matchers-D988Ducb.cjs +0 -2516
  56. package/dist/react/_chunks/pure-DZ97z2oT.cjs +0 -498
  57. package/dist/react/_chunks/pure-PtE2hivW.js +0 -420
  58. package/dist/testing-library/_chunks/aria-snapshot-diff-D7PzpXew.cjs +0 -1170
  59. package/dist/testing-library/_chunks/aria-snapshot-diff-Q8Wj33K0.js +0 -985
@@ -1,2390 +1,29 @@
1
- import { A as implOf, C as agentElementSummary, D as checkContainerType, E as advanceFakeTimersByTime, O as getDocument, T as matchesSelector, _ as nodeKey, a as runWithExpensiveErrorDiagnosticsDisabled, c as prettyFormat, h as hiddenReason, i as getConfig, j as jestFakeTimersAreEnabled, k as getWindowFromNode, l as ariaSnapshot, o as logDOM, p as describeElement, r as configure, s as prettyDOM, t as diffAriaSnapshots, v as nodeProps, w as envDebugFormat, x as truncate, y as quote } from "./_chunks/aria-snapshot-diff-Q8Wj33K0.js";
2
- import { createRequire } from "node:module";
3
- import { $impl, ELEMENT_NODE, F_HTML, HTML_NS, T, TEXT_NODE, asciiLowercase, attr, describeCall, describeNode, getComputedStyleOverride, nextInTree, tracePromise, traceSync, tracing, treeRoot } from "@ctrl/dom/internal";
4
- import { roleSupportsProp } from "@ctrl/dom/aria";
5
- import { computeAccessibleDescriptionImpl, computeAccessibleNameImpl, implicitRole, isInaccessibleImpl, isInaccessibleWithStyle, isSubtreeInaccessibleImpl, isVisibilityHidden as isVisibilityHidden$1, tlRole, tlRoleMatches } from "@ctrl/dom/aria/internal";
6
- import { AsyncLocalStorage } from "node:async_hooks";
1
+ import{A as e,C as t,D as n,E as r,M as i,N as a,O as o,T as s,_ as c,a as l,c as u,h as d,i as f,j as p,k as m,l as h,o as g,p as _,r as v,s as y,t as b,v as x,w as S,x as C,y as w}from"./_chunks/aria-snapshot-diff-B1L8s_sM.js";import{$impl as T,ELEMENT_NODE as E,F_HTML as ee,HTML_NS as D,T as O,TEXT_NODE as te,asciiLowercase as k,attr as A,describeCall as j,describeNode as ne,getComputedStyleOverride as re,nextInTree as M,tracePromise as ie,traceSync as ae,tracing as N,treeRoot as oe}from"@ctrl/dom/internal";import{roleSupportsProp as se}from"@ctrl/dom/aria";import{computeAccessibleDescriptionImpl as ce,computeAccessibleNameImpl as P,implicitRole as le,isInaccessibleImpl as F,isInaccessibleWithStyle as ue,isSubtreeInaccessibleImpl as de,isVisibilityHidden as fe,tlRole as I,tlRoleMatches as L}from"@ctrl/dom/aria/internal";import{AsyncLocalStorage as pe}from"node:async_hooks";function isLabelable(e){if(e.type!==E||e.ns!==D)return!1;switch(e.tag){case O.button:case O.meter:case O.output:case O.progress:case O.select:case O.textarea:return!0;case O.input:{let t=A(e,`type`);return t===null||k(t)!==`hidden`}}return!1}function isLabelledNodeName(e){if(e.prefix!==null)return!1;switch(k(e.name)){case`button`:case`meter`:case`output`:case`progress`:case`select`:case`textarea`:case`input`:return!0}return!1}function labelControl(e,t){let n=A(e,`for`);if(n!==null){if(n===``)return null;let e=t().get(n)??null;return e!==null&&isLabelable(e)?e:null}for(let t=e.first;t!==null;t=M(t,e))if(isLabelable(t))return t;return null}function buildIdMap(e,t){let n=/* @__PURE__ */ new Map;t&&e.type===E&&e.id!==``&&n.set(e.id,e);for(let t=e.first;t!==null;t=M(t,e))t.type===E&&t.id!==``&&!n.has(t.id)&&n.set(t.id,t);return n}var LabelContext=class{container;labelsByControl;containerIds;constructor(e){this.container=e,this.labelsByControl=null,this.containerIds=null}labelsOf(e){if(!isLabelable(e))return R;let t=this.labelsByControl;return t===null&&(t=this.labelsByControl=buildLabelMap(oe(e))),t.get(e)??R}byIdInContainer(e){let t=this.containerIds;return t===null&&(t=this.containerIds=buildIdMap(this.container,!1)),t.get(e)??null}};const R=[];function buildLabelMap(e){let t=/* @__PURE__ */ new Map,n=null,getIds=()=>n??=buildIdMap(e,!0);for(let n=e;n!==null;n=M(n,e)){if(n.type!==E||n.tag!==O.label||n.ns!==D)continue;let e=labelControl(n,getIds);if(e===null)continue;let r=t.get(e);r===void 0?t.set(e,[n]):r.push(n)}return t}function getTextContent(e){if(e.type===E&&isLabelledNodeName(e))return``;if(e.type===te)return e.data;let t=``;for(let n=e.first;n!==null;n=n.next)t+=getTextContent(n);return t}function getLabelContentImpl(e){if(e.tag===O.label&&e.ns===D)return getTextContent(e);let t=e.node;return t.value||t.textContent}const me=/* @__PURE__ */ new Set([`button`,`input`,`meter`,`output`,`progress`,`select`,`textarea`]);function labelledFormControl(e,t){for(let n=e.first;n!==null;n=M(n,e))if(n.type===E&&me.has(n.name)&&(t===`*`||s(n,t)))return n}function getLabelsImpl(e,t,n=`*`){let r=A(t,`aria-labelledby`),i=r?r.split(` `):[];return i.length?i.map(t=>{let n=e.byIdInContainer(t);return n?{content:getLabelContentImpl(n),formControl:null}:{content:``,formControl:null}}):e.labelsOf(t).map(e=>({content:getLabelContentImpl(e),formControl:labelledFormControl(e,n)}))}function assertNotNullOrUndefined(e){if(e==null)throw Error(`It looks like ${e} was passed instead of a matcher. Did you do something like getByText(${e})?`)}function fuzzyMatches(e,t,n,r){if(typeof e!=`string`)return!1;assertNotNullOrUndefined(n);let i=r(e);return typeof n==`string`||typeof n==`number`?i.toLowerCase().includes(n.toString().toLowerCase()):typeof n==`function`?n(i,t):matchRegExp(n,i)}function matches$1(e,t,n,r){if(typeof e!=`string`)return!1;assertNotNullOrUndefined(n);let i=r(e);return n instanceof Function?n(i,t):n instanceof RegExp?matchRegExp(n,i):i===String(n)}a(matches$1,`matches`);function isRegExpWhitespace(e){return e<=32?e===32||e>=9&&e<=13:e<160?!1:e===160||e===5760||e>=8192&&e<=8202||e===8232||e===8233||e===8239||e===8287||e===12288||e===65279}function changedByNormalizing(e,t,n){let r=e.length-1,i=!1;for(let a=0;a<=r;a++){let o=e.charCodeAt(a),s=isRegExpWhitespace(o);if(s&&(t&&(a===0||a===r)||n&&(i||o!==32)))return!0;i=s}return!1}const he=/\s+/g;function getDefaultNormalizer({trim:e=!0,collapseWhitespace:t=!0}={}){return n=>{if(!changedByNormalizing(n,e,t))return n;let r=n;return r=e?r.trim():r,r=t?r.replace(he,` `):r,r}}const ge=getDefaultNormalizer();function makeNormalizer({trim:e,collapseWhitespace:t,normalizer:n}){if(!n)return e===void 0&&t===void 0?ge:getDefaultNormalizer({trim:e,collapseWhitespace:t});if(e!==void 0||t!==void 0)throw Error(`trim and collapseWhitespace are not supported with a normalizer. If you want to use the default trim and collapseWhitespace logic in your normalizer, use "getDefaultNormalizer({trim, collapseWhitespace})" and compose that into your normalizer`);return n}function matchRegExp(e,t){let n=e.test(t);return e.global&&e.lastIndex!==0&&(console.warn(`To match all elements we had to reset the lastIndex of the RegExp because the global flag is enabled. We encourage to remove the global flag from the RegExp.`),e.lastIndex=0),n}function isButtonLikeInput(e){if(e.tag!==O.input||e.ns!==D)return!1;let t=A(e,`type`);if(t===null)return!1;let n=k(t);return n===`submit`||n===`button`||n===`reset`}function getNodeTextImpl(e){if(isButtonLikeInput(e))return e.node.value;let t=``;for(let n=e.first;n!==null;n=n.next)n.type===te&&(t+=n.data);return t}function getNodeText(t){let n=e(t);return n.type===E?getNodeTextImpl(n):t.matches(`input[type=submit], input[type=button], input[type=reset]`)}const _e={computedStyleSupportsPseudoElements:!0};function styleOverride(e){return re(e)}function nameOptions(e,t){return t===null?e?_e:void 0:{computedStyleSupportsPseudoElements:e,getComputedStyle:t}}const z={implicitRole(e){let t=le(e);return t===``?null:t},roleMatches:L,roleSupportsProp(e,t){return typeof e==`string`&&se(e,t)},computeAccessibleName(e,t,n){return P(e,nameOptions(t,n),5)},computeAccessibleDescription(e,t,n){return ce(e,nameOptions(t,n),5)},isInaccessible:F,isInaccessibleWithStyle:ue,isSubtreeInaccessible:de};function parentElement(e){let t=e.parent;return t!==null&&t.type===E?t:null}function isInaccessibleImpl$1(e){return z.isInaccessible(e)}a(isInaccessibleImpl$1,`isInaccessibleImpl`);function isInaccessibleChecked(e){let t=styleOverride(e);return t===null?z.isInaccessible(e):z.isInaccessibleWithStyle(e,t,null)}function isInaccessible(t,n={}){let r=e(t),i=n.isSubtreeInaccessible,a=styleOverride(r);if(i===void 0)return a===null?isInaccessibleImpl$1(r):z.isInaccessibleWithStyle(r,a,null);if(a===null?fe(r):a(t).visibility===`hidden`)return!0;for(let e=r;e!==null;e=parentElement(e))if(i(e.node))return!0;return!1}function getImplicitAriaRolesImpl(e){let t=z.implicitRole(e);return t===null?[]:[t]}function getRoles(t,{hidden:n=!1}={}){let r=e(t),i={},a=n===!1?styleOverride(r):null,o=a===null?null:/* @__PURE__ */ new Map,visit=e=>{if(n!==!1||(a===null?isInaccessibleImpl$1(e):z.isInaccessibleWithStyle(e,a,o))===!1){let t=A(e,`role`),n=t===null?getImplicitAriaRolesImpl(e):t.split(` `).slice(0,1);for(let t of n){let n=i[t];Array.isArray(n)?n.push(e.node):i[t]=[e.node]}}for(let t=e.first;t!==null;t=t.next)t.type===E&&visit(t)};return visit(r),i}const ve={format:`pretty`};function prettyRoles(t,{hidden:n,includeDescription:r}){let i=getRoles(t,{hidden:n}),a=f().computedStyleSupportsPseudoElements,o=styleOverride(e(t));return Object.entries(i).filter(([e])=>e!==`generic`).map(([t,n])=>{let i=`-`.repeat(50);return`${t}:\n\n${n.map(t=>{let n=e(t),i=`Name "${z.computeAccessibleName(n,a,o)}":\n`,s=y(t.cloneNode(!1),void 0,ve);return r?`${i}${`Description "${z.computeAccessibleDescription(n,a,o)}":\n`}${s}`:`${i}${s}`}).join(`
7
2
 
8
- // \0rolldown/runtime.js
9
- var __defProp = Object.defineProperty;
10
- var __exportAll = (all, no_symbols) => {
11
- let target = {};
12
- for (var name in all) {
13
- __defProp(target, name, {
14
- get: all[name],
15
- enumerable: true
16
- });
17
- }
18
- if (!no_symbols) {
19
- __defProp(target, Symbol.toStringTag, { value: "Module" });
20
- }
21
- return target;
22
- };
23
-
24
- // src/label-helpers.ts
25
- /** https://html.spec.whatwg.org/#category-label (form-associated custom elements not supported). */
26
- function isLabelable(impl) {
27
- if (impl.type !== ELEMENT_NODE || impl.ns !== HTML_NS) return false;
28
- switch (impl.tag) {
29
- case T.button:
30
- case T.meter:
31
- case T.output:
32
- case T.progress:
33
- case T.select:
34
- case T.textarea: return true;
35
- case T.input: {
36
- const type = attr(impl, "type");
37
- return type === null || asciiLowercase(type) !== "hidden";
38
- }
39
- }
40
- return false;
41
- }
42
- /** `labelledNodeNames` upstream: elements whose text is excluded from a label's content. */
43
- function isLabelledNodeName(impl) {
44
- if (impl.prefix !== null) return false;
45
- switch (asciiLowercase(impl.name)) {
46
- case "button":
47
- case "meter":
48
- case "output":
49
- case "progress":
50
- case "select":
51
- case "textarea":
52
- case "input": return true;
53
- }
54
- return false;
55
- }
56
- /** https://html.spec.whatwg.org/#labeled-control */
57
- function labelControl(label, ids) {
58
- const htmlFor = attr(label, "for");
59
- if (htmlFor !== null) {
60
- if (htmlFor === "") return null;
61
- const el = ids().get(htmlFor) ?? null;
62
- return el !== null && isLabelable(el) ? el : null;
63
- }
64
- for (let n = label.first; n !== null; n = nextInTree(n, label)) if (isLabelable(n)) return n;
65
- return null;
66
- }
67
- /** First element (tree order) per id in `root`'s subtree, root excluded unless `inclusive`. */
68
- function buildIdMap(root, inclusive) {
69
- const ids = /* @__PURE__ */ new Map();
70
- if (inclusive && root.type === ELEMENT_NODE && root.id !== "") ids.set(root.id, root);
71
- for (let n = root.first; n !== null; n = nextInTree(n, root)) if (n.type === ELEMENT_NODE && n.id !== "" && !ids.has(n.id)) ids.set(n.id, n);
72
- return ids;
73
- }
74
- /** Per-query memo: label associations of the container's tree and container-scoped id lookups. */
75
- var LabelContext = class {
76
- container;
77
- labelsByControl;
78
- containerIds;
79
- constructor(container) {
80
- this.container = container;
81
- this.labelsByControl = null;
82
- this.containerIds = null;
83
- }
84
- /** `element.labels` (empty for non-labelable elements) — label elements in tree order. */
85
- labelsOf(el) {
86
- if (!isLabelable(el)) return EMPTY;
87
- let map = this.labelsByControl;
88
- if (map === null) map = this.labelsByControl = buildLabelMap(treeRoot(el));
89
- return map.get(el) ?? EMPTY;
90
- }
91
- /** `container.querySelector('[id="…"]')` */
92
- byIdInContainer(id) {
93
- let ids = this.containerIds;
94
- if (ids === null) ids = this.containerIds = buildIdMap(this.container, false);
95
- return ids.get(id) ?? null;
96
- }
97
- };
98
- const EMPTY = [];
99
- function buildLabelMap(root) {
100
- const map = /* @__PURE__ */ new Map();
101
- let ids = null;
102
- const getIds = () => ids ??= buildIdMap(root, true);
103
- for (let n = root; n !== null; n = nextInTree(n, root)) {
104
- if (n.type !== ELEMENT_NODE || n.tag !== T.label || n.ns !== HTML_NS) continue;
105
- const control = labelControl(n, getIds);
106
- if (control === null) continue;
107
- const list = map.get(control);
108
- if (list === void 0) map.set(control, [n]);
109
- else list.push(n);
110
- }
111
- return map;
112
- }
113
- function getTextContent(node) {
114
- if (node.type === ELEMENT_NODE && isLabelledNodeName(node)) return "";
115
- if (node.type === TEXT_NODE) return node.data;
116
- let text = "";
117
- for (let c = node.first; c !== null; c = c.next) text += getTextContent(c);
118
- return text;
119
- }
120
- function getLabelContentImpl(element) {
121
- if (element.tag === T.label && element.ns === HTML_NS) return getTextContent(element);
122
- const node = element.node;
123
- return node.value || node.textContent;
124
- }
125
- const FORM_CONTROL_TAGS = /* @__PURE__ */ new Set([
126
- "button",
127
- "input",
128
- "meter",
129
- "output",
130
- "progress",
131
- "select",
132
- "textarea"
133
- ]);
134
- /** `label.querySelectorAll('button, input, meter, output, progress, select, textarea')` filtered by `selector`, first hit. */
135
- function labelledFormControl(label, selector) {
136
- for (let n = label.first; n !== null; n = nextInTree(n, label)) {
137
- if (n.type !== ELEMENT_NODE) continue;
138
- if (!FORM_CONTROL_TAGS.has(n.name)) continue;
139
- if (selector === "*" || matchesSelector(n, selector)) return n;
140
- }
141
- }
142
- function getLabelsImpl(ctx, element, selector = "*") {
143
- const ariaLabelledBy = attr(element, "aria-labelledby");
144
- const labelsId = ariaLabelledBy ? ariaLabelledBy.split(" ") : [];
145
- if (labelsId.length) return labelsId.map((labelId) => {
146
- const labellingElement = ctx.byIdInContainer(labelId);
147
- return labellingElement ? {
148
- content: getLabelContentImpl(labellingElement),
149
- formControl: null
150
- } : {
151
- content: "",
152
- formControl: null
153
- };
154
- });
155
- return ctx.labelsOf(element).map((label) => ({
156
- content: getLabelContentImpl(label),
157
- formControl: labelledFormControl(label, selector)
158
- }));
159
- }
160
-
161
- // src/matches.ts
162
- function assertNotNullOrUndefined(matcher) {
163
- if (matcher === null || matcher === void 0) throw new Error(`It looks like ${matcher} was passed instead of a matcher. Did you do something like getByText(${matcher})?`);
164
- }
165
- function fuzzyMatches(textToMatch, node, matcher, normalizer) {
166
- if (typeof textToMatch !== "string") return false;
167
- assertNotNullOrUndefined(matcher);
168
- const normalizedText = normalizer(textToMatch);
169
- if (typeof matcher === "string" || typeof matcher === "number") return normalizedText.toLowerCase().includes(matcher.toString().toLowerCase());
170
- else if (typeof matcher === "function") return matcher(normalizedText, node);
171
- else return matchRegExp(matcher, normalizedText);
172
- }
173
- function matches$1(textToMatch, node, matcher, normalizer) {
174
- if (typeof textToMatch !== "string") return false;
175
- assertNotNullOrUndefined(matcher);
176
- const normalizedText = normalizer(textToMatch);
177
- if (matcher instanceof Function) return matcher(normalizedText, node);
178
- else if (matcher instanceof RegExp) return matchRegExp(matcher, normalizedText);
179
- else return normalizedText === String(matcher);
180
- }
181
- /**
182
- * Whether code unit `c` is matched by the RegExp `\s` class, which is also the set
183
- * `String.prototype.trim` removes (https://tc39.es/ecma262/#sec-compiletocharset — WhiteSpace
184
- * and LineTerminator).
185
- */
186
- function isRegExpWhitespace(c) {
187
- if (c <= 32) return c === 32 || c >= 9 && c <= 13;
188
- if (c < 160) return false;
189
- return c === 160 || c === 5760 || c >= 8192 && c <= 8202 || c === 8232 || c === 8233 || c === 8239 || c === 8287 || c === 12288 || c === 65279;
190
- }
191
- /**
192
- * Whether `trim()` and/or `replace(/\s+/g, " ")` would change `s`. When not, the default
193
- * normalizer returns its input as is: text like "Row 12 label" (single spaces, nothing to trim)
194
- * is the common case, and the two passes would allocate two new strings per candidate node.
195
- */
196
- function changedByNormalizing(s, trim, collapse) {
197
- const last = s.length - 1;
198
- let prevWhitespace = false;
199
- for (let i = 0; i <= last; i++) {
200
- const c = s.charCodeAt(i);
201
- const ws = isRegExpWhitespace(c);
202
- if (ws) {
203
- if (trim && (i === 0 || i === last)) return true;
204
- if (collapse && (prevWhitespace || c !== 32)) return true;
205
- }
206
- prevWhitespace = ws;
207
- }
208
- return false;
209
- }
210
- const WHITESPACE_RUN = /\s+/g;
211
- function getDefaultNormalizer({ trim = true, collapseWhitespace = true } = {}) {
212
- return (text) => {
213
- if (!changedByNormalizing(text, trim, collapseWhitespace)) return text;
214
- let normalizedText = text;
215
- normalizedText = trim ? normalizedText.trim() : normalizedText;
216
- normalizedText = collapseWhitespace ? normalizedText.replace(WHITESPACE_RUN, " ") : normalizedText;
217
- return normalizedText;
218
- };
219
- }
220
- const defaultNormalizer = getDefaultNormalizer();
221
- /**
222
- * Constructs a normalizer to pass to functions in matches.ts
223
- * @param trim The user-specified value for `trim`, without any defaulting having been applied
224
- * @param collapseWhitespace The user-specified value for `collapseWhitespace`, without any defaulting having been applied
225
- * @param normalizer The user-specified normalizer
226
- */
227
- function makeNormalizer({ trim, collapseWhitespace, normalizer }) {
228
- if (!normalizer) {
229
- if (trim === void 0 && collapseWhitespace === void 0) return defaultNormalizer;
230
- return getDefaultNormalizer({
231
- trim,
232
- collapseWhitespace
233
- });
234
- }
235
- if (typeof trim !== "undefined" || typeof collapseWhitespace !== "undefined") throw new Error("trim and collapseWhitespace are not supported with a normalizer. If you want to use the default trim and collapseWhitespace logic in your normalizer, use \"getDefaultNormalizer({trim, collapseWhitespace})\" and compose that into your normalizer");
236
- return normalizer;
237
- }
238
- function matchRegExp(matcher, text) {
239
- const match = matcher.test(text);
240
- if (matcher.global && matcher.lastIndex !== 0) {
241
- console.warn(`To match all elements we had to reset the lastIndex of the RegExp because the global flag is enabled. We encourage to remove the global flag from the RegExp.`);
242
- matcher.lastIndex = 0;
243
- }
244
- return match;
245
- }
246
-
247
- // src/get-node-text.ts
248
- /** `el.matches('input[type=submit], input[type=button], input[type=reset]')` without the selector engine. */
249
- function isButtonLikeInput(impl) {
250
- if (impl.tag !== T.input || impl.ns !== HTML_NS) return false;
251
- const type = attr(impl, "type");
252
- if (type === null) return false;
253
- const t = asciiLowercase(type);
254
- return t === "submit" || t === "button" || t === "reset";
255
- }
256
- /** Concatenated data of the direct Text children (or a button-like input's value). */
257
- function getNodeTextImpl(impl) {
258
- if (isButtonLikeInput(impl)) return impl.node.value;
259
- let text = "";
260
- for (let c = impl.first; c !== null; c = c.next) if (c.type === TEXT_NODE) text += c.data;
261
- return text;
262
- }
263
- function getNodeText(node) {
264
- const impl = implOf(node);
265
- if (impl.type !== ELEMENT_NODE) return node.matches("input[type=submit], input[type=button], input[type=reset]");
266
- return getNodeTextImpl(impl);
267
- }
268
-
269
- // src/aria.ts
270
- const PSEUDO_OPTIONS = { computedStyleSupportsPseudoElements: true };
271
- /**
272
- * The user-replaced `window.getComputedStyle` of `el`'s window, or null (the fast path).
273
- * Upstream reads every style through `window.getComputedStyle`, so test setups that replace it
274
- * (Sentry: `el => el.style`) change what ByRole considers hidden and how names are computed.
275
- * Callers check once per query/call and pass the result to the functions below.
276
- */
277
- function styleOverride(el) {
278
- return getComputedStyleOverride(el);
279
- }
280
- /** dom-accessibility-api 0.5 options for testing-library's `computedStyleSupportsPseudoElements` config. */
281
- function nameOptions(computedStyleSupportsPseudoElements, gcs) {
282
- if (gcs !== null) return {
283
- computedStyleSupportsPseudoElements,
284
- getComputedStyle: gcs
285
- };
286
- return computedStyleSupportsPseudoElements ? PSEUDO_OPTIONS : void 0;
287
- }
288
- const aria = {
289
- /** First implicit ARIA role (aria-query 5.3.0 `elementRoles` semantics), or null. */
290
- implicitRole(el) {
291
- const r = implicitRole(el);
292
- return r === "" ? null : r;
293
- },
294
- /** Testing Library's role filter (explicit first token / any token with queryFallbacks / implicit). */
295
- roleMatches: tlRoleMatches,
296
- /** `roles.get(role)?.props[prop] !== undefined` (aria-query 5.3.0). */
297
- roleSupportsProp(role, prop) {
298
- return typeof role === "string" && roleSupportsProp(role, prop);
299
- },
300
- /** `gcs`: `styleOverride(el)` (or null), checked once by the caller. */
301
- computeAccessibleName(el, computedStyleSupportsPseudoElements, gcs) {
302
- return computeAccessibleNameImpl(el, nameOptions(computedStyleSupportsPseudoElements, gcs), 5);
303
- },
304
- computeAccessibleDescription(el, computedStyleSupportsPseudoElements, gcs) {
305
- return computeAccessibleDescriptionImpl(el, nameOptions(computedStyleSupportsPseudoElements, gcs), 5);
306
- },
307
- /** Testing Library's `isInaccessible(element)` (default subtree check, memoized per node). */
308
- isInaccessible: isInaccessibleImpl,
309
- /**
310
- * `isInaccessible(element, { isSubtreeInaccessible: cached })` reading styles through a
311
- * user-replaced getComputedStyle; `memo` is the per-query subtree cache (or null).
312
- */
313
- isInaccessibleWithStyle,
314
- isSubtreeInaccessible: isSubtreeInaccessibleImpl
315
- };
316
-
317
- // src/role-helpers.ts
318
- /** `element.parentElement` */
319
- function parentElement(el) {
320
- const p = el.parent;
321
- return p !== null && p.type === ELEMENT_NODE ? p : null;
322
- }
323
- /**
324
- * Partial implementation https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion
325
- * which should only be used for elements with a non-presentational role i.e.
326
- * `role="none"` and `role="presentation"` will not be excluded.
327
- *
328
- * Implements aria-hidden semantics (i.e. parent overrides child)
329
- * Ignores "Child Presentational: True" characteristics
330
- *
331
- * The default subtree check is memoized per element by @ctrl/dom/aria (stamped with the document
332
- * version), which covers upstream's per-query `subtreeIsInaccessibleCache` and more.
333
- */
334
- function isInaccessibleImpl$1(element) {
335
- return aria.isInaccessible(element);
336
- }
337
- /**
338
- * `isInaccessible(element)` for one-off callers (suggestions): honors a user-replaced
339
- * `window.getComputedStyle` like upstream, at the cost of one check per call.
340
- */
341
- function isInaccessibleChecked(element) {
342
- const gcs = styleOverride(element);
343
- return gcs === null ? aria.isInaccessible(element) : aria.isInaccessibleWithStyle(element, gcs, null);
344
- }
345
- function isInaccessible(element, options = {}) {
346
- const impl = implOf(element);
347
- const custom = options.isSubtreeInaccessible;
348
- const gcs = styleOverride(impl);
349
- if (custom === void 0) return gcs === null ? isInaccessibleImpl$1(impl) : aria.isInaccessibleWithStyle(impl, gcs, null);
350
- if (gcs !== null ? gcs(element).visibility === "hidden" : isVisibilityHidden$1(impl)) return true;
351
- for (let current = impl; current !== null; current = parentElement(current)) if (custom(current.node)) return true;
352
- return false;
353
- }
354
- /** Explicit role token or implicit role, as `getRoles` groups them ("" for `role=""`). */
355
- function getImplicitAriaRolesImpl(el) {
356
- const role = aria.implicitRole(el);
357
- return role === null ? [] : [role];
358
- }
359
- function getRoles(container, { hidden = false } = {}) {
360
- const root = implOf(container);
361
- const roles = {};
362
- const gcs = hidden !== false ? null : styleOverride(root);
363
- const memo = gcs !== null ? /* @__PURE__ */ new Map() : null;
364
- const visit = (node) => {
365
- if (hidden !== false || (gcs === null ? isInaccessibleImpl$1(node) : aria.isInaccessibleWithStyle(node, gcs, memo)) === false) {
366
- const explicit = attr(node, "role");
367
- const nodeRoles = explicit !== null ? explicit.split(" ").slice(0, 1) : getImplicitAriaRolesImpl(node);
368
- for (const role of nodeRoles) {
369
- const list = roles[role];
370
- if (Array.isArray(list)) list.push(node.node);
371
- else roles[role] = [node.node];
372
- }
373
- }
374
- for (let c = node.first; c !== null; c = c.next) if (c.type === ELEMENT_NODE) visit(c);
375
- };
376
- visit(root);
377
- return roles;
378
- }
379
- const PRETTY = { format: "pretty" };
380
- function prettyRoles(dom, { hidden, includeDescription }) {
381
- const roles = getRoles(dom, { hidden });
382
- const pseudo = getConfig().computedStyleSupportsPseudoElements;
383
- const gcs = styleOverride(implOf(dom));
384
- return Object.entries(roles).filter(([role]) => role !== "generic").map(([role, elements]) => {
385
- const delimiterBar = "-".repeat(50);
386
- return `${role}:\n\n${elements.map((el) => {
387
- const impl = implOf(el);
388
- const nameString = `Name "${aria.computeAccessibleName(impl, pseudo, gcs)}":\n`;
389
- const domString = prettyDOM(el.cloneNode(false), void 0, PRETTY);
390
- if (includeDescription) return `${nameString}${`Description "${aria.computeAccessibleDescription(impl, pseudo, gcs)}":\n`}${domString}`;
391
- return `${nameString}${domString}`;
392
- }).join("\n\n")}\n\n${delimiterBar}`;
393
- }).join("\n");
394
- }
395
- const logRoles = (dom, { hidden = false } = {}) => console.log(prettyRoles(dom, { hidden }));
396
- function checkBooleanAttribute(element, attribute) {
397
- const attributeValue = attr(element, attribute);
398
- if (attributeValue === "true") return true;
399
- if (attributeValue === "false") return false;
400
- }
401
- /** false/true if (not)selected, undefined if not selectable */
402
- function computeAriaSelected$1(element) {
403
- if (element.tag === T.option && element.ns === HTML_NS) return element.node.selected;
404
- return checkBooleanAttribute(element, "aria-selected");
405
- }
406
- function computeAriaBusy$1(element) {
407
- return attr(element, "aria-busy") === "true";
408
- }
409
- /** false/true if (not)checked, undefined if not checked-able */
410
- function computeAriaChecked(element) {
411
- const node = element.node;
412
- if ("indeterminate" in node && node.indeterminate) return;
413
- if ("checked" in node) return node.checked;
414
- return checkBooleanAttribute(element, "aria-checked");
415
- }
416
- function computeAriaPressed(element) {
417
- return checkBooleanAttribute(element, "aria-pressed");
418
- }
419
- function computeAriaCurrent$1(element) {
420
- return checkBooleanAttribute(element, "aria-current") ?? attr(element, "aria-current") ?? false;
421
- }
422
- function computeAriaExpanded$1(element) {
423
- return checkBooleanAttribute(element, "aria-expanded");
424
- }
425
- /** number if implicit heading or aria-level present, otherwise undefined */
426
- function computeHeadingLevelImpl(element) {
427
- const level = attr(element, "aria-level");
428
- const ariaLevelAttribute = level && Number(level);
429
- if (ariaLevelAttribute) return ariaLevelAttribute;
430
- if (element.ns !== HTML_NS) return void 0;
431
- switch (element.tag) {
432
- case T.h1: return 1;
433
- case T.h2: return 2;
434
- case T.h3: return 3;
435
- case T.h4: return 4;
436
- case T.h5: return 5;
437
- case T.h6: return 6;
438
- }
439
- }
440
- function computeAriaValueNow(element) {
441
- const valueNow = attr(element, "aria-valuenow");
442
- return valueNow === null ? void 0 : +valueNow;
443
- }
444
- function computeAriaValueMax(element) {
445
- const valueMax = attr(element, "aria-valuemax");
446
- return valueMax === null ? void 0 : +valueMax;
447
- }
448
- function computeAriaValueMin(element) {
449
- const valueMin = attr(element, "aria-valuemin");
450
- return valueMin === null ? void 0 : +valueMin;
451
- }
452
- function computeAriaValueText(element) {
453
- const valueText = attr(element, "aria-valuetext");
454
- return valueText === null ? void 0 : valueText;
455
- }
456
-
457
- // src/suggestions.ts
458
- const normalize$1 = getDefaultNormalizer();
459
- function escapeRegExp(string) {
460
- return string.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
461
- }
462
- function getRegExpMatcher(string) {
463
- return new RegExp(escapeRegExp(string.toLowerCase()), "i");
464
- }
465
- function makeSuggestion(queryName, element, content, { variant, name }) {
466
- let warning = "";
467
- const queryOptions = {};
468
- const queryArgs = [["Role", "TestId"].includes(queryName) ? content : getRegExpMatcher(content)];
469
- if (name) queryOptions.name = getRegExpMatcher(name);
470
- if (queryName === "Role" && isInaccessibleChecked(implOf(element))) {
471
- queryOptions.hidden = true;
472
- warning = `Element is inaccessible. This means that the element and all its children are invisible to screen readers.
3
+ `)}\n\n${i}`}).join(`
4
+ `)}const logRoles=(e,{hidden:t=!1}={})=>console.log(prettyRoles(e,{hidden:t}));function checkBooleanAttribute(e,t){let n=A(e,t);if(n===`true`)return!0;if(n===`false`)return!1}function computeAriaSelected$1(e){return e.tag===O.option&&e.ns===D?e.node.selected:checkBooleanAttribute(e,`aria-selected`)}a(computeAriaSelected$1,`computeAriaSelected`);function computeAriaBusy$1(e){return A(e,`aria-busy`)===`true`}a(computeAriaBusy$1,`computeAriaBusy`);function computeAriaChecked(e){let t=e.node;if(!(`indeterminate`in t&&t.indeterminate))return`checked`in t?t.checked:checkBooleanAttribute(e,`aria-checked`)}function computeAriaPressed(e){return checkBooleanAttribute(e,`aria-pressed`)}function computeAriaCurrent$1(e){return checkBooleanAttribute(e,`aria-current`)??A(e,`aria-current`)??!1}a(computeAriaCurrent$1,`computeAriaCurrent`);function computeAriaExpanded$1(e){return checkBooleanAttribute(e,`aria-expanded`)}a(computeAriaExpanded$1,`computeAriaExpanded`);function computeHeadingLevelImpl(e){let t=A(e,`aria-level`),n=t&&Number(t);if(n)return n;if(e.ns===D)switch(e.tag){case O.h1:return 1;case O.h2:return 2;case O.h3:return 3;case O.h4:return 4;case O.h5:return 5;case O.h6:return 6}}function computeAriaValueNow(e){let t=A(e,`aria-valuenow`);return t===null?void 0:+t}function computeAriaValueMax(e){let t=A(e,`aria-valuemax`);return t===null?void 0:+t}function computeAriaValueMin(e){let t=A(e,`aria-valuemin`);return t===null?void 0:+t}function computeAriaValueText(e){let t=A(e,`aria-valuetext`);return t===null?void 0:t}const B=getDefaultNormalizer();function escapeRegExp(e){return e.replace(/[.*+\-?^${}()|[\]\\]/g,`\\$&`)}function getRegExpMatcher(e){return new RegExp(escapeRegExp(e.toLowerCase()),`i`)}function makeSuggestion(t,n,r,{variant:i,name:a}){let o=``,s={},c=[[`Role`,`TestId`].includes(t)?r:getRegExpMatcher(r)];a&&(s.name=getRegExpMatcher(a)),t===`Role`&&isInaccessibleChecked(e(n))&&(s.hidden=!0,o=`Element is inaccessible. This means that the element and all its children are invisible to screen readers.
473
5
  If you are using the aria-hidden prop, make sure this is the right choice for your case.
474
- `;
475
- }
476
- if (Object.keys(queryOptions).length > 0) queryArgs.push(queryOptions);
477
- const queryMethod = `${variant}By${queryName}`;
478
- return {
479
- queryName,
480
- queryMethod,
481
- queryArgs,
482
- variant,
483
- warning,
484
- toString() {
485
- if (warning) console.warn(warning);
486
- let [text, options] = queryArgs;
487
- text = typeof text === "string" ? `'${text}'` : text;
488
- options = options ? `, { ${Object.entries(options).map(([k, v]) => `${k}: ${v}`).join(", ")} }` : "";
489
- return `${queryMethod}(${text}${options})`;
490
- }
491
- };
492
- }
493
- function canSuggest(currentMethod, requestedMethod, data) {
494
- return Boolean(data && (!requestedMethod || requestedMethod.toLowerCase() === currentMethod.toLowerCase()));
495
- }
496
- function getSuggestedQuery(element, variant = "get", method) {
497
- const impl = implOf(element);
498
- if (matchesSelector(impl, getConfig().defaultIgnore)) return;
499
- const role = attr(impl, "role") ?? getImplicitAriaRolesImpl(impl)?.[0];
500
- if (role !== "generic" && canSuggest("Role", method, role)) return makeSuggestion("Role", element, role, {
501
- variant,
502
- name: aria.computeAccessibleName(impl, getConfig().computedStyleSupportsPseudoElements, styleOverride(impl))
503
- });
504
- const labelText = getLabelsImpl(new LabelContext(implOf(getDocument())), impl).map((label) => label.content).join(" ");
505
- if (canSuggest("LabelText", method, labelText)) return makeSuggestion("LabelText", element, labelText, { variant });
506
- const placeholderText = attr(impl, "placeholder");
507
- if (canSuggest("PlaceholderText", method, placeholderText)) return makeSuggestion("PlaceholderText", element, placeholderText, { variant });
508
- const textContent = normalize$1(getNodeTextImpl(impl));
509
- if (canSuggest("Text", method, textContent)) return makeSuggestion("Text", element, textContent, { variant });
510
- if (canSuggest("DisplayValue", method, element.value)) return makeSuggestion("DisplayValue", element, normalize$1(element.value), { variant });
511
- const alt = attr(impl, "alt");
512
- if (canSuggest("AltText", method, alt)) return makeSuggestion("AltText", element, alt, { variant });
513
- const title = attr(impl, "title");
514
- if (canSuggest("Title", method, title)) return makeSuggestion("Title", element, title, { variant });
515
- const testId = element.getAttribute(getConfig().testIdAttribute);
516
- if (canSuggest("TestId", method, testId)) return makeSuggestion("TestId", element, testId, { variant });
517
- }
6
+ `),Object.keys(s).length>0&&c.push(s);let l=`${i}By${t}`;return{queryName:t,queryMethod:l,queryArgs:c,variant:i,warning:o,toString(){o&&console.warn(o);let[e,t]=c;return e=typeof e==`string`?`'${e}'`:e,t=t?`, { ${Object.entries(t).map(([e,t])=>`${e}: ${t}`).join(`, `)} }`:``,`${l}(${e}${t})`}}}function canSuggest(e,t,n){return!(!n||t&&t.toLowerCase()!==e.toLowerCase())}function getSuggestedQuery(t,n=`get`,r){let i=e(t);if(s(i,f().defaultIgnore))return;let a=A(i,`role`)??getImplicitAriaRolesImpl(i)?.[0];if(a!==`generic`&&canSuggest(`Role`,r,a))return makeSuggestion(`Role`,t,a,{variant:n,name:z.computeAccessibleName(i,f().computedStyleSupportsPseudoElements,styleOverride(i))});let c=getLabelsImpl(new LabelContext(e(o())),i).map(e=>e.content).join(` `);if(canSuggest(`LabelText`,r,c))return makeSuggestion(`LabelText`,t,c,{variant:n});let l=A(i,`placeholder`);if(canSuggest(`PlaceholderText`,r,l))return makeSuggestion(`PlaceholderText`,t,l,{variant:n});let u=B(getNodeTextImpl(i));if(canSuggest(`Text`,r,u))return makeSuggestion(`Text`,t,u,{variant:n});if(canSuggest(`DisplayValue`,r,t.value))return makeSuggestion(`DisplayValue`,t,B(t.value),{variant:n});let d=A(i,`alt`);if(canSuggest(`AltText`,r,d))return makeSuggestion(`AltText`,t,d,{variant:n});let p=A(i,`title`);if(canSuggest(`Title`,r,p))return makeSuggestion(`Title`,t,p,{variant:n});let m=t.getAttribute(f().testIdAttribute);if(canSuggest(`TestId`,r,m))return makeSuggestion(`TestId`,t,m,{variant:n})}function copyStackTrace(e,t){e.stack=t.stack.replace(t.message,e.message)}function waitForImpl(e,{container:t=o(),timeout:i=f().asyncUtilTimeout,showOriginalStackTrace:a=f().showOriginalStackTrace,stackTraceError:s,interval:c=50,onTimeout:u=e=>(e.name===`TestingLibraryElementError`&&S()!==null||Object.defineProperty(e,"message",{value:f().getElementError(e.message,t).message}),e),mutationObserverOptions:d={subtree:!0,childList:!0,attributes:!0,characterData:!0}},h=null){if(typeof e!=`function`)throw TypeError("Received `callback` arg must be a function");return new Promise(async(o,g)=>{let _,v,y,b=!1,x=`idle`,S=setTimeout(handleTimeout,i),C=p();if(C){let{unstable_advanceTimersWrapper:e}=f();for(checkCallback();!b;){if(!p()){let e=/* @__PURE__ */ Error(`Changed from using fake timers to real timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to real timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`);a||copyStackTrace(e,s),g(e);return}if(await e(async()=>{r(c)}),b)break;checkCallback()}}else{try{n(t)}catch(e){b=!0,clearTimeout(S),g(e);return}let e=h===null?null:pe.snapshot(),r=e===null?checkRealTimersCallback:()=>e(checkRealTimersCallback);v=setInterval(r,c);let{MutationObserver:i}=m(t);y=new i(r),y.observe(t,d),checkCallback()}function onDone(e,t){b=!0,clearTimeout(S),C||(clearInterval(v),y.disconnect()),e?g(e):o(t)}function checkRealTimersCallback(){if(p()){let e=/* @__PURE__ */ Error(`Changed from using real timers to fake timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to fake timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`);return a||copyStackTrace(e,s),g(e)}return checkCallback()}function checkCallback(){if(x!==`pending`){h!==null&&(h.data.checks=(h.data.checks??0)+1);try{let t=l(e);typeof t?.then==`function`?(x=`pending`,t.then(e=>{x=`resolved`,onDone(null,e)},e=>{x=`rejected`,_=e})):onDone(null,t)}catch(e){_=e}}}function handleTimeout(){let e;_?(e=_,!a&&e.name===`TestingLibraryElementError`&&copyStackTrace(e,s)):(e=/* @__PURE__ */ Error(`Timed out in waitFor.`),a||copyStackTrace(e,s)),onDone(u(e),null)}})}function waitFor(e,t){return N()?ie(`testing-library.wait_for`,`waitFor(${describeCallback(e)})`,n=>waitForInSpan(e,t,n)):waitForInSpan(e,t,null)}function waitForInSpan(e,t,n){let r=/* @__PURE__ */ Error(`STACK_TRACE_MESSAGE`);return f().asyncWrapper(()=>waitForImpl(e,{stackTraceError:r,...t},n))}function describeCallback(e){if(typeof e!=`function`)return String(e);let t=Function.prototype.toString.call(e).replace(/\s+/g,` `).replace(/__vite_ssr_import_\d+__\./g,``).replace(/\(0, ?([\w$.]+)\)/g,`$1`).replace(/(?<![\w$.])_[a-z][\w$]*\.(?=[\w$])/g,``),n=/^(async )?\(\) ?=> ?\{ ?(?:return )?(.*?);? ?\}$/.exec(t);return n!==null&&!n[2].includes(`;`)&&(t=`${n[1]??``}() => ${n[2]}`),t.length>120?`${t.slice(0,119)}…`:t}function getElementError(e,t){return f().getElementError(e,t)}function getMultipleElementsFoundError(e,t){return getElementError(`${e}\n\n(If this is intentional, then use the \`*AllBy*\` variant of the query (like \`queryAllByText\`, \`getAllByText\`, or \`findAllByText\`)).`,t)}function queryAllByAttribute(t,n,r,{exact:i=!0,collapseWhitespace:a,trim:o,normalizer:s}={}){let c=i?matches$1:fuzzyMatches,l=makeNormalizer({collapseWhitespace:a,trim:o,normalizer:s}),u=e(n),d=k(t),f=[];for(let e=u.first;e!==null;e=M(e,u)){if(e.type!==E||e.attrs===null)continue;let n=A(e,(e.flags&ee)===0?t:d);n!==null&&c(n,e.node,r,l)&&f.push(e.node)}return f}function queryByAttribute(e,t,n,r){let i=queryAllByAttribute(e,t,n,r);if(i.length>1)throw getMultipleElementsFoundError(`Found multiple elements by [${e}=${n}]`,t);return i[0]||null}function makeSingleQuery(e,n){return(r,...i)=>{let a=e(r,...i);if(a.length>1){let e=S()===null?a.map(e=>getElementError(null,e).message).join(`
518
7
 
519
- // src/wait-for.ts
520
- function copyStackTrace(target, source) {
521
- target.stack = source.stack.replace(source.message, target.message);
522
- }
523
- function waitForImpl(callback, { container = getDocument(), timeout = getConfig().asyncUtilTimeout, showOriginalStackTrace = getConfig().showOriginalStackTrace, stackTraceError, interval = 50, onTimeout = (error) => {
524
- if (error.name === "TestingLibraryElementError" && envDebugFormat() !== null) return error;
525
- Object.defineProperty(error, "message", { value: getConfig().getElementError(error.message, container).message });
526
- return error;
527
- }, mutationObserverOptions = {
528
- subtree: true,
529
- childList: true,
530
- attributes: true,
531
- characterData: true
532
- } }, span = null) {
533
- if (typeof callback !== "function") throw new TypeError("Received `callback` arg must be a function");
534
- return new Promise(async (resolve, reject) => {
535
- let lastError;
536
- let intervalId;
537
- let observer;
538
- let finished = false;
539
- let promiseStatus = "idle";
540
- const overallTimeoutTimer = setTimeout(handleTimeout, timeout);
541
- const usingJestFakeTimers = jestFakeTimersAreEnabled();
542
- if (usingJestFakeTimers) {
543
- const { unstable_advanceTimersWrapper: advanceTimersWrapper } = getConfig();
544
- checkCallback();
545
- while (!finished) {
546
- if (!jestFakeTimersAreEnabled()) {
547
- const error = /* @__PURE__ */ new Error(`Changed from using fake timers to real timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to real timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`);
548
- if (!showOriginalStackTrace) copyStackTrace(error, stackTraceError);
549
- reject(error);
550
- return;
551
- }
552
- await advanceTimersWrapper(async () => {
553
- advanceFakeTimersByTime(interval);
554
- });
555
- if (finished) break;
556
- checkCallback();
557
- }
558
- } else {
559
- try {
560
- checkContainerType(container);
561
- } catch (e) {
562
- finished = true;
563
- clearTimeout(overallTimeoutTimer);
564
- reject(e);
565
- return;
566
- }
567
- const inSpan = span !== null ? AsyncLocalStorage.snapshot() : null;
568
- const onTick = inSpan === null ? checkRealTimersCallback : () => inSpan(checkRealTimersCallback);
569
- intervalId = setInterval(onTick, interval);
570
- const { MutationObserver } = getWindowFromNode(container);
571
- observer = new MutationObserver(onTick);
572
- observer.observe(container, mutationObserverOptions);
573
- checkCallback();
574
- }
575
- function onDone(error, result) {
576
- finished = true;
577
- clearTimeout(overallTimeoutTimer);
578
- if (!usingJestFakeTimers) {
579
- clearInterval(intervalId);
580
- observer.disconnect();
581
- }
582
- if (error) reject(error);
583
- else resolve(result);
584
- }
585
- function checkRealTimersCallback() {
586
- if (jestFakeTimersAreEnabled()) {
587
- const error = /* @__PURE__ */ new Error(`Changed from using real timers to fake timers while using waitFor. This is not allowed and will result in very strange behavior. Please ensure you're awaiting all async things your test is doing before changing to fake timers. For more info, please go to https://github.com/testing-library/dom-testing-library/issues/830`);
588
- if (!showOriginalStackTrace) copyStackTrace(error, stackTraceError);
589
- return reject(error);
590
- } else return checkCallback();
591
- }
592
- function checkCallback() {
593
- if (promiseStatus === "pending") return;
594
- if (span !== null) span.data.checks = (span.data.checks ?? 0) + 1;
595
- try {
596
- const result = runWithExpensiveErrorDiagnosticsDisabled(callback);
597
- if (typeof result?.then === "function") {
598
- promiseStatus = "pending";
599
- result.then((resolvedValue) => {
600
- promiseStatus = "resolved";
601
- onDone(null, resolvedValue);
602
- }, (rejectedValue) => {
603
- promiseStatus = "rejected";
604
- lastError = rejectedValue;
605
- });
606
- } else onDone(null, result);
607
- } catch (error) {
608
- lastError = error;
609
- }
610
- }
611
- function handleTimeout() {
612
- let error;
613
- if (lastError) {
614
- error = lastError;
615
- if (!showOriginalStackTrace && error.name === "TestingLibraryElementError") copyStackTrace(error, stackTraceError);
616
- } else {
617
- error = /* @__PURE__ */ new Error("Timed out in waitFor.");
618
- if (!showOriginalStackTrace) copyStackTrace(error, stackTraceError);
619
- }
620
- onDone(onTimeout(error), null);
621
- }
622
- });
623
- }
624
- function waitFor(callback, options) {
625
- if (!tracing()) return waitForInSpan(callback, options, null);
626
- return tracePromise("testing-library.wait_for", `waitFor(${describeCallback(callback)})`, (span) => waitForInSpan(callback, options, span));
627
- }
628
- /** waitFor without a span of its own, counting the callback's runs on `span` (findBy* passes its query span). */
629
- function waitForInSpan(callback, options, span) {
630
- const stackTraceError = /* @__PURE__ */ new Error("STACK_TRACE_MESSAGE");
631
- return getConfig().asyncWrapper(() => waitForImpl(callback, {
632
- stackTraceError,
633
- ...options
634
- }, span));
635
- }
636
- /**
637
- * A callback's source on one line, shortened: `() => expect(screen.getByText("Done")).toBeVisible()`.
638
- * Undoes what transforms do to imported names: Vite's `__vite_ssr_import_0__.screen`, the
639
- * `(0, expect)(…)` call form (Vite, Babel) and CommonJS interop objects (`_reactTestingLibrary.screen`,
640
- * Babel and SWC), and drops the braces around a single statement.
641
- */
642
- function describeCallback(callback) {
643
- if (typeof callback !== "function") return String(callback);
644
- let source = Function.prototype.toString.call(callback).replace(/\s+/g, " ").replace(/__vite_ssr_import_\d+__\./g, "").replace(/\(0, ?([\w$.]+)\)/g, "$1").replace(/(?<![\w$.])_[a-z][\w$]*\.(?=[\w$])/g, "");
645
- const block = /^(async )?\(\) ?=> ?\{ ?(?:return )?(.*?);? ?\}$/.exec(source);
646
- if (block !== null && !block[2].includes(";")) source = `${block[1] ?? ""}() => ${block[2]}`;
647
- return source.length > 120 ? `${source.slice(0, 119)}…` : source;
648
- }
649
-
650
- // src/query-helpers.ts
651
- function getElementError(message, container) {
652
- return getConfig().getElementError(message, container);
653
- }
654
- function getMultipleElementsFoundError(message, container) {
655
- return getElementError(`${message}\n\n(If this is intentional, then use the \`*AllBy*\` variant of the query (like \`queryAllByText\`, \`getAllByText\`, or \`findAllByText\`)).`, container);
656
- }
657
- function queryAllByAttribute(attribute, container, text, { exact = true, collapseWhitespace, trim, normalizer } = {}) {
658
- const matcher = exact ? matches$1 : fuzzyMatches;
659
- const matchNormalizer = makeNormalizer({
660
- collapseWhitespace,
661
- trim,
662
- normalizer
663
- });
664
- const root = implOf(container);
665
- const lower = asciiLowercase(attribute);
666
- const out = [];
667
- for (let n = root.first; n !== null; n = nextInTree(n, root)) {
668
- if (n.type !== ELEMENT_NODE || n.attrs === null) continue;
669
- const value = attr(n, (n.flags & F_HTML) !== 0 ? lower : attribute);
670
- if (value !== null && matcher(value, n.node, text, matchNormalizer)) out.push(n.node);
671
- }
672
- return out;
673
- }
674
- function queryByAttribute(attribute, container, text, options) {
675
- const els = queryAllByAttribute(attribute, container, text, options);
676
- if (els.length > 1) throw getMultipleElementsFoundError(`Found multiple elements by [${attribute}=${text}]`, container);
677
- return els[0] || null;
678
- }
679
- function makeSingleQuery(allQuery, getMultipleError) {
680
- return (container, ...args) => {
681
- const els = allQuery(container, ...args);
682
- if (els.length > 1) {
683
- const elementStrings = envDebugFormat() !== null ? els.map((element) => agentElementSummary(element)).join("\n") : els.map((element) => getElementError(null, element).message).join("\n\n");
684
- throw getMultipleElementsFoundError(`${getMultipleError(container, ...args)}
8
+ `):a.map(e=>t(e)).join(`
9
+ `);throw getMultipleElementsFoundError(`${n(r,...i)}
685
10
 
686
11
  Here are the matching elements:
687
12
 
688
- ${elementStrings}`, container);
689
- }
690
- return els[0] || null;
691
- };
692
- }
693
- function getSuggestionError(suggestion, container) {
694
- return getConfig().getElementError(`A better query is available, try this:
695
- ${suggestion.toString()}
696
- `, container);
697
- }
698
- function makeGetAllQuery(allQuery, getMissingError) {
699
- return (container, ...args) => {
700
- const els = allQuery(container, ...args);
701
- if (!els.length) throw getConfig().getElementError(getMissingError(container, ...args), container);
702
- return els;
703
- };
704
- }
705
- function makeFindQuery(getter, name = "find") {
706
- return (container, text, options, waitForOptions) => {
707
- const find = (span) => waitForInSpan(() => {
708
- return getter(container, text, options);
709
- }, {
710
- container,
711
- ...waitForOptions
712
- }, span);
713
- if (!tracing()) return find(null);
714
- return tracePromise(QUERY_OP, describeCall(name, [text, options]), async (span) => {
715
- const result = await find(span);
716
- span.data.matches = matchCount(result);
717
- return result;
718
- });
719
- };
720
- }
721
- const QUERY_OP = "testing-library.query";
722
- const matchCount = (result) => Array.isArray(result) ? result.length : result ? 1 : 0;
723
- /** Ours: a span per call when something subscribes to @ctrl/dom's tracing channel (@ctrl/dom trace.ts). */
724
- function traceQuery(name, query) {
725
- return (container, ...args) => {
726
- if (!tracing()) return query(container, ...args);
727
- return traceSync(QUERY_OP, describeCall(name, args), (span) => {
728
- const result = query(container, ...args);
729
- span.data.matches = matchCount(result);
730
- return result;
731
- });
732
- };
733
- }
734
- const wrapSingleQueryWithSuggestion = (query, queryAllByName, variant) => (container, ...args) => {
735
- const element = query(container, ...args);
736
- const [{ suggest = getConfig().throwSuggestions } = {}] = args.slice(-1);
737
- if (element && suggest) {
738
- const suggestion = getSuggestedQuery(element, variant);
739
- if (suggestion && !queryAllByName.endsWith(suggestion.queryName)) throw getSuggestionError(suggestion.toString(), container);
740
- }
741
- return element;
742
- };
743
- const wrapAllByQueryWithSuggestion = (query, queryAllByName, variant) => (container, ...args) => {
744
- const els = query(container, ...args);
745
- const [{ suggest = getConfig().throwSuggestions } = {}] = args.slice(-1);
746
- if (els.length && suggest) {
747
- const uniqueSuggestionMessages = [...new Set(els.map((element) => getSuggestedQuery(element, variant)?.toString()))];
748
- if (uniqueSuggestionMessages.length === 1 && !queryAllByName.endsWith(getSuggestedQuery(els[0], variant).queryName)) throw getSuggestionError(uniqueSuggestionMessages[0], container);
749
- }
750
- return els;
751
- };
752
- function buildQueries(queryAllBy, getMultipleError, getMissingError) {
753
- const queryBy = wrapSingleQueryWithSuggestion(makeSingleQuery(queryAllBy, getMultipleError), queryAllBy.name, "query");
754
- const getAllBy = makeGetAllQuery(queryAllBy, getMissingError);
755
- const getBy = makeSingleQuery(getAllBy, getMultipleError);
756
- const getByWithSuggestions = wrapSingleQueryWithSuggestion(getBy, queryAllBy.name, "get");
757
- const getAllWithSuggestions = wrapAllByQueryWithSuggestion(getAllBy, queryAllBy.name.replace("query", "get"), "getAll");
758
- const by = queryAllBy.name.startsWith("queryAll") ? queryAllBy.name.slice(8) : "";
759
- const findAllBy = makeFindQuery(wrapAllByQueryWithSuggestion(getAllBy, queryAllBy.name, "findAll"), `findAll${by}`);
760
- const findBy = makeFindQuery(wrapSingleQueryWithSuggestion(getBy, queryAllBy.name, "find"), `find${by}`);
761
- return [
762
- traceQuery(`query${by}`, queryBy),
763
- traceQuery(`getAll${by}`, getAllWithSuggestions),
764
- traceQuery(`get${by}`, getByWithSuggestions),
765
- findAllBy,
766
- findBy
767
- ];
768
- }
769
-
770
- // src/candidates.ts
771
- const MAX_CANDIDATES = 10;
772
- const MAX_TEXT = 80;
773
- const PRESENTATIONAL = /* @__PURE__ */ new Set([
774
- "",
775
- "generic",
776
- "none",
777
- "presentation"
778
- ]);
779
- const identity$1 = (text) => text;
780
- function normalize(s) {
781
- return s.replace(/\s+/g, " ").trim();
782
- }
783
- /** Loose similarity for string matchers: 0 = equal ignoring case/space, 1 = substring, 2 = shares a word, -1 = unrelated. */
784
- function similarity(candidate, wanted) {
785
- const a = normalize(candidate).toLowerCase();
786
- const b = normalize(wanted).toLowerCase();
787
- if (a === "" || b === "") return -1;
788
- if (a === b) return 0;
789
- if (a.includes(b) || b.includes(a)) return 1;
790
- const words = b.split(" ");
791
- for (let i = 0; i < words.length; i++) if (words[i].length > 2 && a.includes(words[i])) return 2;
792
- return -1;
793
- }
794
- /** Whether `text` matches `matcher` exactly, or loosely for string matchers (rank), or not at all (-1). */
795
- function closeness(text, node, matcher, normalizer, exact = true) {
796
- if ((exact ? matches$1 : fuzzyMatches)(text, node, matcher, normalizer)) return 0;
797
- if (typeof matcher === "string" || typeof matcher === "number") {
798
- const s = similarity(normalizer(text), String(matcher));
799
- return s === -1 ? -1 : s + 1;
800
- }
801
- return -1;
802
- }
803
- function line(el, role, name, hidden, comment) {
804
- const node = {
805
- role,
806
- name,
807
- props: nodeProps(el, role, false, hidden),
808
- value: null,
809
- url: null,
810
- children: [],
811
- element: el
812
- };
813
- return `- ${nodeKey(node, MAX_TEXT)} # ${comment}`;
814
- }
815
- function format(title, candidates) {
816
- if (candidates.length === 0) return "";
817
- candidates.sort((a, b) => a.rank - b.rank);
818
- const shown = candidates.slice(0, MAX_CANDIDATES).map((c) => c.line);
819
- if (candidates.length > MAX_CANDIDATES) shown.push(`# … ${candidates.length - MAX_CANDIDATES} more`);
820
- return `${title}:\n${shown.join("\n")}`;
821
- }
822
- function nameOf(el) {
823
- return normalize(computeAccessibleNameImpl(el, void 0, 5));
824
- }
825
- /** Closest elements for a failed `*ByRole` query, or "". */
826
- function roleCandidates(container, q) {
827
- const root = implOf(container);
828
- const out = [];
829
- const name = q.name;
830
- for (let el = root.first; el !== null; el = nextInTree(el, root)) {
831
- if (el.type !== ELEMENT_NODE) continue;
832
- const inaccessible = isInaccessibleImpl(el);
833
- const role = tlRole(el);
834
- if (tlRoleMatches(el, q.role, q.queryFallbacks)) {
835
- const elName = nameOf(el);
836
- const nameRank = name === void 0 ? 0 : closeness(elName, el.node, name, identity$1);
837
- const stateOk = q.matchesState(el);
838
- if (nameRank === 0 && stateOk) {
839
- if (inaccessible && !q.hidden) out.push({
840
- line: line(el, role, elName, true, `hidden: ${hiddenReason(el)} (or pass { hidden: true })`),
841
- rank: 0
842
- });
843
- } else if (nameRank === 0) out.push({
844
- line: line(el, role, elName, inaccessible && !q.hidden, `role and name match, state is not ${q.stateHint}`),
845
- rank: 1
846
- });
847
- else if (!inaccessible || q.hidden) out.push({
848
- line: line(el, role, elName, false, nameRank > 0 ? "similar name" : "same role, other name"),
849
- rank: nameRank > 0 ? 2 + nameRank : 10
850
- });
851
- continue;
852
- }
853
- if (name === void 0) continue;
854
- if (!PRESENTATIONAL.has(role)) {
855
- const elName = nameOf(el);
856
- if (elName === "") continue;
857
- const rank = closeness(elName, el.node, name, identity$1);
858
- if (rank >= 0) out.push({
859
- line: line(el, role, elName, inaccessible && !q.hidden, `same name, role "${role}"`),
860
- rank: 2 + rank
861
- });
862
- continue;
863
- }
864
- const text = normalize(getNodeTextImpl(el));
865
- if (text !== "" && closeness(text, el.node, name, identity$1) === 0) out.push({
866
- line: `- text: ${quote(truncate(text, MAX_TEXT))} # in ${describeElement(el)}, which has no role: give it role="${q.role}" or use getByText`,
867
- rank: 2
868
- });
869
- }
870
- return format("Closest matches", out);
871
- }
872
- function roleOrTag(el) {
873
- const role = tlRole(el);
874
- return PRESENTATIONAL.has(role) ? describeElement(el) : role;
875
- }
876
- /** Closest elements for a failed `*ByText` query, or "". */
877
- function textCandidates(container, text, normalizer, selector, ignore, exact) {
878
- if (typeof text === "function") return "";
879
- const root = implOf(container);
880
- const out = [];
881
- const split = [];
882
- for (let el = root.first; el !== null; el = nextInTree(el, root)) {
883
- if (el.type !== ELEMENT_NODE) continue;
884
- if (ignore && typeof ignore === "string" && matchesSelector(el, ignore)) continue;
885
- const own = getNodeTextImpl(el);
886
- const rank = own.trim() === "" ? -1 : closeness(own, el.node, text, normalizer, exact);
887
- if (rank === 0) out.push({
888
- line: `- ${roleOrTag(el)}: ${quote(truncate(normalizer(own), MAX_TEXT))} # matches, but not selector "${selector}"`,
889
- rank: 0
890
- });
891
- else if (rank > 0) out.push({
892
- line: `- ${roleOrTag(el)}: ${quote(truncate(normalizer(own), MAX_TEXT))} # similar text in ${describeElement(el)}`,
893
- rank: 1 + rank
894
- });
895
- if (rank !== 0 && el.first !== null && el.first !== el.last && (exact ? matches$1 : fuzzyMatches)(el.node.textContent, el.node, text, normalizer)) split.push(el);
896
- }
897
- for (let i = 0; i < split.length; i++) {
898
- const el = split[i];
899
- let hasDeeper = false;
900
- for (let j = i + 1; j < split.length && !hasDeeper; j++) if (isAncestor(el, split[j])) hasDeeper = true;
901
- if (hasDeeper) continue;
902
- out.push({
903
- line: `- ${roleOrTag(el)}: ${quote(truncate(normalizer(el.node.textContent), MAX_TEXT))} # text split across child elements of ${describeElement(el)}: use a function matcher or getByRole`,
904
- rank: 0
905
- });
906
- }
907
- return format("Closest matches", out);
908
- }
909
- function isAncestor(a, b) {
910
- for (let p = b.parent; p !== null; p = p.parent) if (p === a) return true;
911
- return false;
912
- }
913
- const LABELLABLE_ROLES = /* @__PURE__ */ new Set([
914
- "textbox",
915
- "searchbox",
916
- "combobox",
917
- "listbox",
918
- "checkbox",
919
- "radio",
920
- "switch",
921
- "slider",
922
- "spinbutton"
923
- ]);
924
- /** Form controls and their accessible names for a failed `*ByLabelText` query, or "". */
925
- function labelCandidates(container, text, normalizer, exact) {
926
- if (typeof text === "function") return "";
927
- const root = implOf(container);
928
- const out = [];
929
- for (let el = root.first; el !== null; el = nextInTree(el, root)) {
930
- if (el.type !== ELEMENT_NODE) continue;
931
- const role = tlRole(el);
932
- if (!LABELLABLE_ROLES.has(role)) continue;
933
- const name = nameOf(el);
934
- const hidden = isInaccessibleImpl(el);
935
- if (name === "") {
936
- const placeholder = attr(el, "placeholder");
937
- const comment = placeholder ? `no label, placeholder ${quote(placeholder)}: use getByPlaceholderText or add a <label>` : `no label: add a <label>, aria-label or aria-labelledby`;
938
- out.push({
939
- line: line(el, role, "", hidden, comment),
940
- rank: placeholder && closeness(placeholder, el.node, text, normalizer) >= 0 ? 1 : 5
941
- });
942
- continue;
943
- }
944
- const rank = closeness(name, el.node, text, normalizer, exact);
945
- out.push({
946
- line: line(el, role, name, hidden, rank >= 0 ? "similar label" : "labelled control"),
947
- rank: rank >= 0 ? 2 + rank : 10
948
- });
949
- }
950
- return format("Labelled form controls", out);
951
- }
952
-
953
- // src/queries/label-text.ts
954
- var label_text_exports = /* @__PURE__ */ __exportAll({
955
- findAllByLabelText: () => findAllByLabelText,
956
- findByLabelText: () => findByLabelText,
957
- getAllByLabelText: () => getAllByLabelTextWithSuggestions,
958
- getByLabelText: () => getByLabelTextWithSuggestions,
959
- queryAllByLabelText: () => queryAllByLabelTextWithSuggestions,
960
- queryByLabelText: () => queryByLabelText
961
- });
962
- function queryAllLabels(container) {
963
- const root = implOf(container);
964
- const out = [];
965
- for (let n = root.first; n !== null; n = nextInTree(n, root)) {
966
- if (n.type !== ELEMENT_NODE || n.name !== "label" && n.name !== "input") continue;
967
- const textToMatch = getLabelContentImpl(n);
968
- if (textToMatch !== null) out.push({
969
- node: n.node,
970
- textToMatch
971
- });
972
- }
973
- return out;
974
- }
975
- function queryAllLabelsByText(container, text, { exact = true, trim, collapseWhitespace, normalizer } = {}) {
976
- const matcher = exact ? matches$1 : fuzzyMatches;
977
- const matchNormalizer = makeNormalizer({
978
- collapseWhitespace,
979
- trim,
980
- normalizer
981
- });
982
- return queryAllLabels(container).filter(({ node, textToMatch }) => matcher(textToMatch, node, text, matchNormalizer)).map(({ node }) => node);
983
- }
984
- function queryAllByLabelText(container, text, { selector = "*", exact = true, collapseWhitespace, trim, normalizer } = {}) {
985
- checkContainerType(container);
986
- const matcher = exact ? matches$1 : fuzzyMatches;
987
- const matchNormalizer = makeNormalizer({
988
- collapseWhitespace,
989
- trim,
990
- normalizer
991
- });
992
- const root = implOf(container);
993
- const ctx = new LabelContext(root);
994
- const labelledElements = [];
995
- for (let n = root.first; n !== null; n = nextInTree(n, root)) {
996
- if (n.type !== ELEMENT_NODE) continue;
997
- if (attr(n, "aria-labelledby") === null && ctx.labelsOf(n).length === 0) continue;
998
- collectLabelled(ctx, n, selector, matcher, text, matchNormalizer, labelledElements);
999
- }
1000
- const ariaLabelled = queryAllByAttribute("aria-label", container, text, {
1001
- exact,
1002
- normalizer: matchNormalizer
1003
- });
1004
- for (let i = 0; i < ariaLabelled.length; i++) labelledElements.push(ariaLabelled[i]);
1005
- const unique = Array.from(new Set(labelledElements));
1006
- return selector === "*" ? unique : unique.filter((element) => matchesSelector(element[$impl], selector));
1007
- }
1008
- function collectLabelled(ctx, labelledElement, selector, matcher, text, matchNormalizer, labelledElements) {
1009
- const labelList = getLabelsImpl(ctx, labelledElement, selector);
1010
- for (const label of labelList) {
1011
- if (!label.formControl) continue;
1012
- const formControl = label.formControl.node;
1013
- if (matcher(label.content, formControl, text, matchNormalizer)) labelledElements.push(formControl);
1014
- }
1015
- const labelsValue = labelList.filter((label) => Boolean(label.content)).map((label) => label.content);
1016
- const node = labelledElement.node;
1017
- if (matcher(labelsValue.join(" "), node, text, matchNormalizer)) labelledElements.push(node);
1018
- if (labelsValue.length > 1) labelsValue.forEach((labelValue, index) => {
1019
- if (matcher(labelValue, node, text, matchNormalizer)) labelledElements.push(node);
1020
- const labelsFiltered = [...labelsValue];
1021
- labelsFiltered.splice(index, 1);
1022
- if (labelsFiltered.length > 1) {
1023
- if (matcher(labelsFiltered.join(" "), node, text, matchNormalizer)) labelledElements.push(node);
1024
- }
1025
- });
1026
- }
1027
- function getAllByLabelText(container, text, ...rest) {
1028
- const els = queryAllByLabelText(container, text, ...rest);
1029
- if (!els.length) {
1030
- const labels = queryAllLabelsByText(container, text, ...rest);
1031
- if (labels.length) {
1032
- const tagNames = labels.map((label) => getTagNameOfElementAssociatedWithLabelViaFor(container, label)).filter((tagName) => !!tagName);
1033
- if (tagNames.length) throw getConfig().getElementError(tagNames.map((tagName) => `Found a label with the text of: ${text}, however the element associated with this label (<${tagName} />) is non-labellable [https://html.spec.whatwg.org/multipage/forms.html#category-label]. If you really need to label a <${tagName} />, you can use aria-label or aria-labelledby instead.`).join("\n\n"), container);
1034
- else throw getConfig().getElementError(`Found a label with the text of: ${text}, however no form control was found associated to that label. Make sure you're using the "for" attribute or "aria-labelledby" attribute correctly.`, container);
1035
- } else throw getConfig().getElementError(withLabelCandidates(`Unable to find a label with the text of: ${text}`, container, text, rest[0]), container);
1036
- }
1037
- return els;
1038
- }
1039
- /** Ours: under CTRL_DOM_DEBUG, append the form controls and their names. */
1040
- function withLabelCandidates(message, container, text, options = {}) {
1041
- if (envDebugFormat() === null) return message;
1042
- const { exact = true, trim, collapseWhitespace, normalizer } = options;
1043
- const candidates = labelCandidates(container, text, makeNormalizer({
1044
- trim,
1045
- collapseWhitespace,
1046
- normalizer
1047
- }), exact);
1048
- return candidates === "" ? message : `${message}\n\n${candidates}`;
1049
- }
1050
- function getTagNameOfElementAssociatedWithLabelViaFor(container, label) {
1051
- const htmlFor = label.getAttribute("for");
1052
- if (!htmlFor) return null;
1053
- const element = new LabelContext(implOf(container)).byIdInContainer(htmlFor);
1054
- return element ? element.node.tagName.toLowerCase() : null;
1055
- }
1056
- const getMultipleError$7 = (c, text) => `Found multiple elements with the text of: ${text}`;
1057
- const queryByLabelText = wrapSingleQueryWithSuggestion(makeSingleQuery(queryAllByLabelText, getMultipleError$7), queryAllByLabelText.name, "query");
1058
- const getByLabelText = makeSingleQuery(getAllByLabelText, getMultipleError$7);
1059
- const findAllByLabelText = makeFindQuery(wrapAllByQueryWithSuggestion(getAllByLabelText, getAllByLabelText.name, "findAll"));
1060
- const findByLabelText = makeFindQuery(wrapSingleQueryWithSuggestion(getByLabelText, getAllByLabelText.name, "find"));
1061
- const getAllByLabelTextWithSuggestions = wrapAllByQueryWithSuggestion(getAllByLabelText, getAllByLabelText.name, "getAll");
1062
- const getByLabelTextWithSuggestions = wrapSingleQueryWithSuggestion(getByLabelText, getAllByLabelText.name, "get");
1063
- const queryAllByLabelTextWithSuggestions = wrapAllByQueryWithSuggestion(queryAllByLabelText, queryAllByLabelText.name, "queryAll");
1064
-
1065
- // src/queries/placeholder-text.ts
1066
- var placeholder_text_exports = /* @__PURE__ */ __exportAll({
1067
- findAllByPlaceholderText: () => findAllByPlaceholderText,
1068
- findByPlaceholderText: () => findByPlaceholderText,
1069
- getAllByPlaceholderText: () => getAllByPlaceholderText,
1070
- getByPlaceholderText: () => getByPlaceholderText,
1071
- queryAllByPlaceholderText: () => queryAllByPlaceholderTextWithSuggestions,
1072
- queryByPlaceholderText: () => queryByPlaceholderText
1073
- });
1074
- function queryAllByPlaceholderText(...args) {
1075
- checkContainerType(args[0]);
1076
- return queryAllByAttribute("placeholder", ...args);
1077
- }
1078
- const getMultipleError$6 = (c, text) => `Found multiple elements with the placeholder text of: ${text}`;
1079
- const getMissingError$6 = (c, text) => `Unable to find an element with the placeholder text of: ${text}`;
1080
- const queryAllByPlaceholderTextWithSuggestions = wrapAllByQueryWithSuggestion(queryAllByPlaceholderText, queryAllByPlaceholderText.name, "queryAll");
1081
- const [queryByPlaceholderText, getAllByPlaceholderText, getByPlaceholderText, findAllByPlaceholderText, findByPlaceholderText] = buildQueries(queryAllByPlaceholderText, getMultipleError$6, getMissingError$6);
1082
-
1083
- // src/queries/text.ts
1084
- var text_exports = /* @__PURE__ */ __exportAll({
1085
- findAllByText: () => findAllByText,
1086
- findByText: () => findByText,
1087
- getAllByText: () => getAllByText,
1088
- getByText: () => getByText,
1089
- queryAllByText: () => queryAllByTextWithSuggestions,
1090
- queryByText: () => queryByText
1091
- });
1092
- /** Whether `ignore` is exactly the default "script, style" list (any element named script/style). */
1093
- function isScriptStyleIgnore(ignore) {
1094
- return ignore === "script, style" || ignore === "script,style";
1095
- }
1096
- function isScriptOrStyle(n) {
1097
- const name = n.name;
1098
- return name === "script" || name === "style";
1099
- }
1100
- function queryAllByText(container, text, { selector = "*", exact = true, collapseWhitespace, trim, ignore = getConfig().defaultIgnore, normalizer } = {}) {
1101
- checkContainerType(container);
1102
- const matcher = exact ? matches$1 : fuzzyMatches;
1103
- const matchNormalizer = makeNormalizer({
1104
- collapseWhitespace,
1105
- trim,
1106
- normalizer
1107
- });
1108
- const root = implOf(container);
1109
- const anySelector = selector === "*";
1110
- const fastIgnore = isScriptStyleIgnore(ignore);
1111
- const out = [];
1112
- const visit = (n) => {
1113
- if (!anySelector && !matchesSelector(n, selector)) return;
1114
- if (ignore) {
1115
- if (fastIgnore ? isScriptOrStyle(n) : matchesSelector(n, ignore)) return;
1116
- }
1117
- if (matcher(getNodeTextImpl(n), n.node, text, matchNormalizer)) out.push(n.node);
1118
- };
1119
- if (root.type === ELEMENT_NODE) visit(root);
1120
- for (let n = root.first; n !== null; n = nextInTree(n, root)) if (n.type === ELEMENT_NODE) visit(n);
1121
- return out;
1122
- }
1123
- const getMultipleError$5 = (c, text) => `Found multiple elements with the text: ${text}`;
1124
- const getMissingError$5 = (c, text, options = {}) => {
1125
- const { collapseWhitespace, trim, normalizer, selector } = options;
1126
- const matchNormalizer = makeNormalizer({
1127
- collapseWhitespace,
1128
- trim,
1129
- normalizer
1130
- });
1131
- const normalizedText = matchNormalizer(text.toString());
1132
- const isNormalizedDifferent = normalizedText !== text.toString();
1133
- const isCustomSelector = (selector ?? "*") !== "*";
1134
- const message = `Unable to find an element with the text: ${isNormalizedDifferent ? `${normalizedText} (normalized from '${text}')` : text}${isCustomSelector ? `, which matches selector '${selector}'` : ""}. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.`;
1135
- if (envDebugFormat() === null) return message;
1136
- const { exact = true, ignore = getConfig().defaultIgnore } = options;
1137
- const candidates = textCandidates(c, text, matchNormalizer, selector ?? "*", ignore, exact);
1138
- return candidates === "" ? message : `${message}\n\n${candidates}`;
1139
- };
1140
- const queryAllByTextWithSuggestions = wrapAllByQueryWithSuggestion(queryAllByText, queryAllByText.name, "queryAll");
1141
- const [queryByText, getAllByText, getByText, findAllByText, findByText] = buildQueries(queryAllByText, getMultipleError$5, getMissingError$5);
1142
-
1143
- // src/queries/display-value.ts
1144
- var display_value_exports = /* @__PURE__ */ __exportAll({
1145
- findAllByDisplayValue: () => findAllByDisplayValue,
1146
- findByDisplayValue: () => findByDisplayValue,
1147
- getAllByDisplayValue: () => getAllByDisplayValue,
1148
- getByDisplayValue: () => getByDisplayValue,
1149
- queryAllByDisplayValue: () => queryAllByDisplayValueWithSuggestions,
1150
- queryByDisplayValue: () => queryByDisplayValue
1151
- });
1152
- function queryAllByDisplayValue(container, value, { exact = true, collapseWhitespace, trim, normalizer } = {}) {
1153
- checkContainerType(container);
1154
- const matcher = exact ? matches$1 : fuzzyMatches;
1155
- const matchNormalizer = makeNormalizer({
1156
- collapseWhitespace,
1157
- trim,
1158
- normalizer
1159
- });
1160
- const root = implOf(container);
1161
- const out = [];
1162
- for (let n = root.first; n !== null; n = nextInTree(n, root)) {
1163
- if (n.type !== ELEMENT_NODE) continue;
1164
- const name = n.name;
1165
- if (name !== "input" && name !== "textarea" && name !== "select") continue;
1166
- const node = n.node;
1167
- if (n.tag === T.select && n.ns === HTML_NS) {
1168
- const options = node.options;
1169
- let found = false;
1170
- for (let i = 0; i < options.length; i++) {
1171
- const option = options[i];
1172
- if (option.selected && matcher(getNodeTextImpl(option[$impl]), option, value, matchNormalizer)) {
1173
- found = true;
1174
- break;
1175
- }
1176
- }
1177
- if (found) out.push(node);
1178
- } else if (matcher(node.value, node, value, matchNormalizer)) out.push(node);
1179
- }
1180
- return out;
1181
- }
1182
- const getMultipleError$4 = (c, value) => `Found multiple elements with the display value: ${value}.`;
1183
- const getMissingError$4 = (c, value) => `Unable to find an element with the display value: ${value}.`;
1184
- const queryAllByDisplayValueWithSuggestions = wrapAllByQueryWithSuggestion(queryAllByDisplayValue, queryAllByDisplayValue.name, "queryAll");
1185
- const [queryByDisplayValue, getAllByDisplayValue, getByDisplayValue, findAllByDisplayValue, findByDisplayValue] = buildQueries(queryAllByDisplayValue, getMultipleError$4, getMissingError$4);
1186
-
1187
- // src/queries/alt-text.ts
1188
- var alt_text_exports = /* @__PURE__ */ __exportAll({
1189
- findAllByAltText: () => findAllByAltText,
1190
- findByAltText: () => findByAltText,
1191
- getAllByAltText: () => getAllByAltText,
1192
- getByAltText: () => getByAltText,
1193
- queryAllByAltText: () => queryAllByAltTextWithSuggestions,
1194
- queryByAltText: () => queryByAltText
1195
- });
1196
- const VALID_TAG_REGEXP = /^(img|input|area|.+-.+)$/i;
1197
- function queryAllByAltText(container, alt, options = {}) {
1198
- checkContainerType(container);
1199
- return queryAllByAttribute("alt", container, alt, options).filter((node) => VALID_TAG_REGEXP.test(node.tagName));
1200
- }
1201
- const getMultipleError$3 = (c, alt) => `Found multiple elements with the alt text: ${alt}`;
1202
- const getMissingError$3 = (c, alt) => `Unable to find an element with the alt text: ${alt}`;
1203
- const queryAllByAltTextWithSuggestions = wrapAllByQueryWithSuggestion(queryAllByAltText, queryAllByAltText.name, "queryAll");
1204
- const [queryByAltText, getAllByAltText, getByAltText, findAllByAltText, findByAltText] = buildQueries(queryAllByAltText, getMultipleError$3, getMissingError$3);
1205
-
1206
- // src/queries/title.ts
1207
- var title_exports = /* @__PURE__ */ __exportAll({
1208
- findAllByTitle: () => findAllByTitle,
1209
- findByTitle: () => findByTitle,
1210
- getAllByTitle: () => getAllByTitle,
1211
- getByTitle: () => getByTitle,
1212
- queryAllByTitle: () => queryAllByTitleWithSuggestions,
1213
- queryByTitle: () => queryByTitle
1214
- });
1215
- /** `node.tagName.toLowerCase() === 'title' && node.parentElement?.tagName.toLowerCase() === 'svg'` */
1216
- function isSvgTitle(n) {
1217
- const parent = n.parent;
1218
- return asciiLowercase(n.prefix === null ? n.name : n.prefix + ":" + n.name) === "title" && parent !== null && parent.type === ELEMENT_NODE && asciiLowercase(parent.prefix === null ? parent.name : parent.prefix + ":" + parent.name) === "svg";
1219
- }
1220
- function queryAllByTitle(container, text, { exact = true, collapseWhitespace, trim, normalizer } = {}) {
1221
- checkContainerType(container);
1222
- const matcher = exact ? matches$1 : fuzzyMatches;
1223
- const matchNormalizer = makeNormalizer({
1224
- collapseWhitespace,
1225
- trim,
1226
- normalizer
1227
- });
1228
- const root = implOf(container);
1229
- const out = [];
1230
- for (let n = root.first; n !== null; n = nextInTree(n, root)) {
1231
- if (n.type !== ELEMENT_NODE) continue;
1232
- const title = n.attrs === null ? null : attr(n, "title");
1233
- const svgTitle = n.name === "title" && n.parent !== null && n.parent.type === ELEMENT_NODE && n.parent.name === "svg";
1234
- if (title === null && !svgTitle) continue;
1235
- if (matcher(title, n.node, text, matchNormalizer) || isSvgTitle(n) && matcher(getNodeTextImpl(n), n.node, text, matchNormalizer)) out.push(n.node);
1236
- }
1237
- return out;
1238
- }
1239
- const getMultipleError$2 = (c, title) => `Found multiple elements with the title: ${title}.`;
1240
- const getMissingError$2 = (c, title) => `Unable to find an element with the title: ${title}.`;
1241
- const queryAllByTitleWithSuggestions = wrapAllByQueryWithSuggestion(queryAllByTitle, queryAllByTitle.name, "queryAll");
1242
- const [queryByTitle, getAllByTitle, getByTitle, findAllByTitle, findByTitle] = buildQueries(queryAllByTitle, getMultipleError$2, getMissingError$2);
1243
-
1244
- // src/queries/role.ts
1245
- var role_exports = /* @__PURE__ */ __exportAll({
1246
- findAllByRole: () => findAllByRole,
1247
- findByRole: () => findByRole,
1248
- getAllByRole: () => getAllByRole,
1249
- getByRole: () => getByRole,
1250
- queryAllByRole: () => queryAllByRoleWithSuggestions,
1251
- queryByRole: () => queryByRole
1252
- });
1253
- const identity = (text) => text;
1254
- function assertSupported(role, prop) {
1255
- if (!aria.roleSupportsProp(role, prop)) throw new Error(`"${prop}" is not supported on role "${role}".`);
1256
- }
1257
- function queryAllByRole(container, role, { hidden = getConfig().defaultHidden, name, description, queryFallbacks = false, selected, busy, checked, pressed, current, level, expanded, value: { now: valueNow, min: valueMin, max: valueMax, text: valueText } = {} } = {}) {
1258
- checkContainerType(container);
1259
- if (selected !== void 0) assertSupported(role, "aria-selected");
1260
- if (busy !== void 0) assertSupported(role, "aria-busy");
1261
- if (checked !== void 0) assertSupported(role, "aria-checked");
1262
- if (pressed !== void 0) assertSupported(role, "aria-pressed");
1263
- if (current !== void 0) assertSupported(role, "aria-current");
1264
- if (level !== void 0) {
1265
- if (role !== "heading") throw new Error(`Role "${role}" cannot have "level" property.`);
1266
- }
1267
- if (valueNow !== void 0) assertSupported(role, "aria-valuenow");
1268
- if (valueMax !== void 0) assertSupported(role, "aria-valuemax");
1269
- if (valueMin !== void 0) assertSupported(role, "aria-valuemin");
1270
- if (valueText !== void 0) assertSupported(role, "aria-valuetext");
1271
- if (expanded !== void 0) assertSupported(role, "aria-expanded");
1272
- const state = {
1273
- selected,
1274
- busy,
1275
- checked,
1276
- pressed,
1277
- current,
1278
- level,
1279
- expanded,
1280
- valueNow,
1281
- valueMin,
1282
- valueMax,
1283
- valueText
1284
- };
1285
- const pseudo = getConfig().computedStyleSupportsPseudoElements;
1286
- const root = implOf(container);
1287
- const out = [];
1288
- const gcs = styleOverride(root);
1289
- const memo = gcs !== null && hidden === false ? /* @__PURE__ */ new Map() : null;
1290
- for (let el = root.first; el !== null; el = nextInTree(el, root)) {
1291
- if (el.type !== ELEMENT_NODE) continue;
1292
- if (!aria.roleMatches(el, role, queryFallbacks)) continue;
1293
- if (!matchesState(el, state)) continue;
1294
- if (hidden === false && (gcs === null ? isInaccessibleImpl$1(el) : aria.isInaccessibleWithStyle(el, gcs, memo))) continue;
1295
- if (name !== void 0 && !matches$1(aria.computeAccessibleName(el, pseudo, gcs), el.node, name, identity)) continue;
1296
- if (description !== void 0 && !matches$1(aria.computeAccessibleDescription(el, pseudo, gcs), el.node, description, identity)) continue;
1297
- out.push(el.node);
1298
- }
1299
- return out;
1300
- }
1301
- /** ByRole's state filters (upstream's closure `matchesState`); one object per query, no per-element allocation. */
1302
- function matchesState(element, s) {
1303
- if (s.selected !== void 0) return s.selected === computeAriaSelected$1(element);
1304
- if (s.busy !== void 0) return s.busy === computeAriaBusy$1(element);
1305
- if (s.checked !== void 0) return s.checked === computeAriaChecked(element);
1306
- if (s.pressed !== void 0) return s.pressed === computeAriaPressed(element);
1307
- if (s.current !== void 0) return s.current === computeAriaCurrent$1(element);
1308
- if (s.expanded !== void 0) return s.expanded === computeAriaExpanded$1(element);
1309
- if (s.level !== void 0) return s.level === computeHeadingLevelImpl(element);
1310
- if (s.valueNow !== void 0 || s.valueMax !== void 0 || s.valueMin !== void 0 || s.valueText !== void 0) {
1311
- let valueMatches = true;
1312
- if (s.valueNow !== void 0) valueMatches &&= s.valueNow === computeAriaValueNow(element);
1313
- if (s.valueMax !== void 0) valueMatches &&= s.valueMax === computeAriaValueMax(element);
1314
- if (s.valueMin !== void 0) valueMatches &&= s.valueMin === computeAriaValueMin(element);
1315
- if (s.valueText !== void 0) valueMatches &&= matches$1(computeAriaValueText(element) ?? null, element.node, s.valueText, identity);
1316
- return valueMatches;
1317
- }
1318
- return true;
1319
- }
1320
- const getNameHint = (name) => {
1321
- let nameHint = "";
1322
- if (name === void 0) nameHint = "";
1323
- else if (typeof name === "string") nameHint = ` and name "${name}"`;
1324
- else nameHint = ` and name \`${name}\``;
1325
- return nameHint;
1326
- };
1327
- const getMultipleError$1 = (c, role, { name } = {}) => {
1328
- return `Found multiple elements with the role "${role}"${getNameHint(name)}`;
1329
- };
1330
- const getMissingError$1 = (container, role, options = {}) => {
1331
- const { hidden = getConfig().defaultHidden, name, description } = options;
1332
- if (envDebugFormat() !== null) return agentMissingError(container, role, options, hidden);
1333
- if (getConfig()._disableExpensiveErrorDiagnostics) return `Unable to find role="${role}"${getNameHint(name)}`;
1334
- let roles = "";
1335
- Array.from(container.children).forEach((childElement) => {
1336
- roles += prettyRoles(childElement, {
1337
- hidden,
1338
- includeDescription: description !== void 0
1339
- });
1340
- });
1341
- let roleMessage;
1342
- if (roles.length === 0) {
1343
- if (hidden === false) roleMessage = "There are no accessible roles. But there might be some inaccessible roles. If you wish to access them, then set the `hidden` option to `true`. Learn more about this here: https://testing-library.com/docs/dom-testing-library/api-queries#byrole";
1344
- else roleMessage = "There are no available roles.";
1345
- } else roleMessage = `
1346
- Here are the ${hidden === false ? "accessible" : "available"} roles:
1347
-
1348
- ${roles.replace(/\n/g, "\n ").replace(/\n\s\s\n/g, "\n\n")}
1349
- `.trim();
1350
- let nameHint = "";
1351
- if (name === void 0) nameHint = "";
1352
- else if (typeof name === "string") nameHint = ` and name "${name}"`;
1353
- else nameHint = ` and name \`${name}\``;
1354
- let descriptionHint = "";
1355
- if (description === void 0) descriptionHint = "";
1356
- else if (typeof description === "string") descriptionHint = ` and description "${description}"`;
1357
- else descriptionHint = ` and description \`${description}\``;
1358
- return `
1359
- Unable to find an ${hidden === false ? "accessible " : ""}element with the role "${role}"${nameHint}${descriptionHint}
1360
-
1361
- ${roleMessage}`.trim();
1362
- };
1363
- function agentMissingError(container, role, options, hidden) {
1364
- const { name, description, queryFallbacks = false, value: { now: valueNow, min: valueMin, max: valueMax, text: valueText } = {} } = options;
1365
- const { selected, busy, checked, pressed, current, level, expanded } = options;
1366
- const state = {
1367
- selected,
1368
- busy,
1369
- checked,
1370
- pressed,
1371
- current,
1372
- level,
1373
- expanded,
1374
- valueNow,
1375
- valueMin,
1376
- valueMax,
1377
- valueText
1378
- };
1379
- const stateHint = Object.entries({
1380
- selected,
1381
- busy,
1382
- checked,
1383
- pressed,
1384
- current,
1385
- level,
1386
- expanded,
1387
- value: options.value
1388
- }).filter(([, v]) => v !== void 0).map(([k, v]) => `${k}: ${JSON.stringify(v)}`).join(", ");
1389
- const descriptionHint = description === void 0 ? "" : typeof description === "string" ? ` and description "${description}"` : ` and description \`${description}\``;
1390
- const head = `Unable to find an ${hidden === false ? "accessible " : ""}element with the role "${role}"${getNameHint(name)}${descriptionHint}`;
1391
- const candidates = roleCandidates(container, {
1392
- role: String(role),
1393
- name,
1394
- hidden,
1395
- queryFallbacks,
1396
- matchesState: (el) => matchesState(el, state),
1397
- stateHint: `{ ${stateHint} }`
1398
- });
1399
- return candidates === "" ? head : `${head}\n\n${candidates}`;
1400
- }
1401
- const queryAllByRoleWithSuggestions = wrapAllByQueryWithSuggestion(queryAllByRole, queryAllByRole.name, "queryAll");
1402
- const [queryByRole, getAllByRole, getByRole, findAllByRole, findByRole] = buildQueries(queryAllByRole, getMultipleError$1, getMissingError$1);
1403
-
1404
- // src/queries/test-id.ts
1405
- var test_id_exports = /* @__PURE__ */ __exportAll({
1406
- findAllByTestId: () => findAllByTestId,
1407
- findByTestId: () => findByTestId,
1408
- getAllByTestId: () => getAllByTestId,
1409
- getByTestId: () => getByTestId,
1410
- queryAllByTestId: () => queryAllByTestIdWithSuggestions,
1411
- queryByTestId: () => queryByTestId
1412
- });
1413
- const getTestIdAttribute = () => getConfig().testIdAttribute;
1414
- function queryAllByTestId(...args) {
1415
- checkContainerType(args[0]);
1416
- return queryAllByAttribute(getTestIdAttribute(), ...args);
1417
- }
1418
- const getMultipleError = (c, id) => `Found multiple elements by: [${getTestIdAttribute()}="${id}"]`;
1419
- const getMissingError = (c, id) => `Unable to find an element by: [${getTestIdAttribute()}="${id}"]`;
1420
- const queryAllByTestIdWithSuggestions = wrapAllByQueryWithSuggestion(queryAllByTestId, queryAllByTestId.name, "queryAll");
1421
- const [queryByTestId, getAllByTestId, getByTestId, findAllByTestId, findByTestId] = buildQueries(queryAllByTestId, getMultipleError, getMissingError);
1422
-
1423
- // src/queries/ordered.ts
1424
- /**
1425
- * All query functions as a plain object in upstream's key order (module order, then
1426
- * findAllBy/findBy/getAllBy/getBy/queryAllBy/queryBy). An ES module namespace would sort
1427
- * the keys alphabetically; `screen`/`within` key order follows upstream's CJS build.
1428
- */
1429
- function build() {
1430
- const out = {};
1431
- const groups = [
1432
- [label_text_exports, "LabelText"],
1433
- [placeholder_text_exports, "PlaceholderText"],
1434
- [text_exports, "Text"],
1435
- [display_value_exports, "DisplayValue"],
1436
- [alt_text_exports, "AltText"],
1437
- [title_exports, "Title"],
1438
- [role_exports, "Role"],
1439
- [test_id_exports, "TestId"]
1440
- ];
1441
- for (const [mod, name] of groups) for (const variant of [
1442
- "findAllBy",
1443
- "findBy",
1444
- "getAllBy",
1445
- "getBy",
1446
- "queryAllBy",
1447
- "queryBy"
1448
- ]) out[variant + name] = mod[variant + name];
1449
- return out;
1450
- }
1451
- const queries = build();
1452
-
1453
- // src/get-queries-for-element.ts
1454
- /**
1455
- * @param element container
1456
- * @param queries object of functions
1457
- * @param initialValue for reducer
1458
- * @returns object of functions bound to container
1459
- */
1460
- function getQueriesForElement(element, queries$1 = queries, initialValue = {}) {
1461
- return Object.keys(queries$1).reduce((helpers, key) => {
1462
- helpers[key] = queries$1[key].bind(null, element);
1463
- return helpers;
1464
- }, initialValue);
1465
- }
1466
-
1467
- // src/wait-for-element-to-be-removed.ts
1468
- const isRemoved = (result) => !result || Array.isArray(result) && !result.length;
1469
- function initialCheck(elements) {
1470
- if (isRemoved(elements)) throw new Error("The element(s) given to waitForElementToBeRemoved are already removed. waitForElementToBeRemoved requires that the element(s) exist(s) before waiting for removal.");
1471
- }
1472
- async function waitForElementToBeRemoved(callback, options) {
1473
- const timeoutError = /* @__PURE__ */ new Error("Timed out in waitForElementToBeRemoved.");
1474
- if (typeof callback !== "function") {
1475
- initialCheck(callback);
1476
- const getRemainingElements = (Array.isArray(callback) ? callback : [callback]).map((element) => {
1477
- let parent = element.parentElement;
1478
- if (parent === null) return () => null;
1479
- while (parent.parentElement) parent = parent.parentElement;
1480
- return () => parent.contains(element) ? element : null;
1481
- });
1482
- callback = () => getRemainingElements.map((c) => c()).filter(Boolean);
1483
- }
1484
- const cb = callback;
1485
- initialCheck(cb());
1486
- return waitFor(() => {
1487
- let result;
1488
- try {
1489
- result = cb();
1490
- } catch (error) {
1491
- if (error.name === "TestingLibraryElementError") return;
1492
- throw error;
1493
- }
1494
- if (!isRemoved(result)) throw timeoutError;
1495
- }, options);
1496
- }
1497
-
1498
- // src/event-map.ts
1499
- const eventMap = {
1500
- copy: {
1501
- EventType: "ClipboardEvent",
1502
- defaultInit: {
1503
- bubbles: true,
1504
- cancelable: true,
1505
- composed: true
1506
- }
1507
- },
1508
- cut: {
1509
- EventType: "ClipboardEvent",
1510
- defaultInit: {
1511
- bubbles: true,
1512
- cancelable: true,
1513
- composed: true
1514
- }
1515
- },
1516
- paste: {
1517
- EventType: "ClipboardEvent",
1518
- defaultInit: {
1519
- bubbles: true,
1520
- cancelable: true,
1521
- composed: true
1522
- }
1523
- },
1524
- compositionEnd: {
1525
- EventType: "CompositionEvent",
1526
- defaultInit: {
1527
- bubbles: true,
1528
- cancelable: true,
1529
- composed: true
1530
- }
1531
- },
1532
- compositionStart: {
1533
- EventType: "CompositionEvent",
1534
- defaultInit: {
1535
- bubbles: true,
1536
- cancelable: true,
1537
- composed: true
1538
- }
1539
- },
1540
- compositionUpdate: {
1541
- EventType: "CompositionEvent",
1542
- defaultInit: {
1543
- bubbles: true,
1544
- cancelable: true,
1545
- composed: true
1546
- }
1547
- },
1548
- keyDown: {
1549
- EventType: "KeyboardEvent",
1550
- defaultInit: {
1551
- bubbles: true,
1552
- cancelable: true,
1553
- charCode: 0,
1554
- composed: true
1555
- }
1556
- },
1557
- keyPress: {
1558
- EventType: "KeyboardEvent",
1559
- defaultInit: {
1560
- bubbles: true,
1561
- cancelable: true,
1562
- charCode: 0,
1563
- composed: true
1564
- }
1565
- },
1566
- keyUp: {
1567
- EventType: "KeyboardEvent",
1568
- defaultInit: {
1569
- bubbles: true,
1570
- cancelable: true,
1571
- charCode: 0,
1572
- composed: true
1573
- }
1574
- },
1575
- focus: {
1576
- EventType: "FocusEvent",
1577
- defaultInit: {
1578
- bubbles: false,
1579
- cancelable: false,
1580
- composed: true
1581
- }
1582
- },
1583
- blur: {
1584
- EventType: "FocusEvent",
1585
- defaultInit: {
1586
- bubbles: false,
1587
- cancelable: false,
1588
- composed: true
1589
- }
1590
- },
1591
- focusIn: {
1592
- EventType: "FocusEvent",
1593
- defaultInit: {
1594
- bubbles: true,
1595
- cancelable: false,
1596
- composed: true
1597
- }
1598
- },
1599
- focusOut: {
1600
- EventType: "FocusEvent",
1601
- defaultInit: {
1602
- bubbles: true,
1603
- cancelable: false,
1604
- composed: true
1605
- }
1606
- },
1607
- change: {
1608
- EventType: "Event",
1609
- defaultInit: {
1610
- bubbles: true,
1611
- cancelable: false
1612
- }
1613
- },
1614
- input: {
1615
- EventType: "InputEvent",
1616
- defaultInit: {
1617
- bubbles: true,
1618
- cancelable: false,
1619
- composed: true
1620
- }
1621
- },
1622
- invalid: {
1623
- EventType: "Event",
1624
- defaultInit: {
1625
- bubbles: false,
1626
- cancelable: true
1627
- }
1628
- },
1629
- submit: {
1630
- EventType: "Event",
1631
- defaultInit: {
1632
- bubbles: true,
1633
- cancelable: true
1634
- }
1635
- },
1636
- reset: {
1637
- EventType: "Event",
1638
- defaultInit: {
1639
- bubbles: true,
1640
- cancelable: true
1641
- }
1642
- },
1643
- click: {
1644
- EventType: "MouseEvent",
1645
- defaultInit: {
1646
- bubbles: true,
1647
- cancelable: true,
1648
- button: 0,
1649
- composed: true
1650
- }
1651
- },
1652
- contextMenu: {
1653
- EventType: "MouseEvent",
1654
- defaultInit: {
1655
- bubbles: true,
1656
- cancelable: true,
1657
- composed: true
1658
- }
1659
- },
1660
- dblClick: {
1661
- EventType: "MouseEvent",
1662
- defaultInit: {
1663
- bubbles: true,
1664
- cancelable: true,
1665
- composed: true
1666
- }
1667
- },
1668
- drag: {
1669
- EventType: "DragEvent",
1670
- defaultInit: {
1671
- bubbles: true,
1672
- cancelable: true,
1673
- composed: true
1674
- }
1675
- },
1676
- dragEnd: {
1677
- EventType: "DragEvent",
1678
- defaultInit: {
1679
- bubbles: true,
1680
- cancelable: false,
1681
- composed: true
1682
- }
1683
- },
1684
- dragEnter: {
1685
- EventType: "DragEvent",
1686
- defaultInit: {
1687
- bubbles: true,
1688
- cancelable: true,
1689
- composed: true
1690
- }
1691
- },
1692
- dragExit: {
1693
- EventType: "DragEvent",
1694
- defaultInit: {
1695
- bubbles: true,
1696
- cancelable: false,
1697
- composed: true
1698
- }
1699
- },
1700
- dragLeave: {
1701
- EventType: "DragEvent",
1702
- defaultInit: {
1703
- bubbles: true,
1704
- cancelable: false,
1705
- composed: true
1706
- }
1707
- },
1708
- dragOver: {
1709
- EventType: "DragEvent",
1710
- defaultInit: {
1711
- bubbles: true,
1712
- cancelable: true,
1713
- composed: true
1714
- }
1715
- },
1716
- dragStart: {
1717
- EventType: "DragEvent",
1718
- defaultInit: {
1719
- bubbles: true,
1720
- cancelable: true,
1721
- composed: true
1722
- }
1723
- },
1724
- drop: {
1725
- EventType: "DragEvent",
1726
- defaultInit: {
1727
- bubbles: true,
1728
- cancelable: true,
1729
- composed: true
1730
- }
1731
- },
1732
- mouseDown: {
1733
- EventType: "MouseEvent",
1734
- defaultInit: {
1735
- bubbles: true,
1736
- cancelable: true,
1737
- composed: true
1738
- }
1739
- },
1740
- mouseEnter: {
1741
- EventType: "MouseEvent",
1742
- defaultInit: {
1743
- bubbles: false,
1744
- cancelable: false,
1745
- composed: true
1746
- }
1747
- },
1748
- mouseLeave: {
1749
- EventType: "MouseEvent",
1750
- defaultInit: {
1751
- bubbles: false,
1752
- cancelable: false,
1753
- composed: true
1754
- }
1755
- },
1756
- mouseMove: {
1757
- EventType: "MouseEvent",
1758
- defaultInit: {
1759
- bubbles: true,
1760
- cancelable: true,
1761
- composed: true
1762
- }
1763
- },
1764
- mouseOut: {
1765
- EventType: "MouseEvent",
1766
- defaultInit: {
1767
- bubbles: true,
1768
- cancelable: true,
1769
- composed: true
1770
- }
1771
- },
1772
- mouseOver: {
1773
- EventType: "MouseEvent",
1774
- defaultInit: {
1775
- bubbles: true,
1776
- cancelable: true,
1777
- composed: true
1778
- }
1779
- },
1780
- mouseUp: {
1781
- EventType: "MouseEvent",
1782
- defaultInit: {
1783
- bubbles: true,
1784
- cancelable: true,
1785
- composed: true
1786
- }
1787
- },
1788
- select: {
1789
- EventType: "Event",
1790
- defaultInit: {
1791
- bubbles: true,
1792
- cancelable: false
1793
- }
1794
- },
1795
- touchCancel: {
1796
- EventType: "TouchEvent",
1797
- defaultInit: {
1798
- bubbles: true,
1799
- cancelable: false,
1800
- composed: true
1801
- }
1802
- },
1803
- touchEnd: {
1804
- EventType: "TouchEvent",
1805
- defaultInit: {
1806
- bubbles: true,
1807
- cancelable: true,
1808
- composed: true
1809
- }
1810
- },
1811
- touchMove: {
1812
- EventType: "TouchEvent",
1813
- defaultInit: {
1814
- bubbles: true,
1815
- cancelable: true,
1816
- composed: true
1817
- }
1818
- },
1819
- touchStart: {
1820
- EventType: "TouchEvent",
1821
- defaultInit: {
1822
- bubbles: true,
1823
- cancelable: true,
1824
- composed: true
1825
- }
1826
- },
1827
- resize: {
1828
- EventType: "UIEvent",
1829
- defaultInit: {
1830
- bubbles: false,
1831
- cancelable: false
1832
- }
1833
- },
1834
- scroll: {
1835
- EventType: "UIEvent",
1836
- defaultInit: {
1837
- bubbles: false,
1838
- cancelable: false
1839
- }
1840
- },
1841
- wheel: {
1842
- EventType: "WheelEvent",
1843
- defaultInit: {
1844
- bubbles: true,
1845
- cancelable: true,
1846
- composed: true
1847
- }
1848
- },
1849
- abort: {
1850
- EventType: "Event",
1851
- defaultInit: {
1852
- bubbles: false,
1853
- cancelable: false
1854
- }
1855
- },
1856
- canPlay: {
1857
- EventType: "Event",
1858
- defaultInit: {
1859
- bubbles: false,
1860
- cancelable: false
1861
- }
1862
- },
1863
- canPlayThrough: {
1864
- EventType: "Event",
1865
- defaultInit: {
1866
- bubbles: false,
1867
- cancelable: false
1868
- }
1869
- },
1870
- durationChange: {
1871
- EventType: "Event",
1872
- defaultInit: {
1873
- bubbles: false,
1874
- cancelable: false
1875
- }
1876
- },
1877
- emptied: {
1878
- EventType: "Event",
1879
- defaultInit: {
1880
- bubbles: false,
1881
- cancelable: false
1882
- }
1883
- },
1884
- encrypted: {
1885
- EventType: "Event",
1886
- defaultInit: {
1887
- bubbles: false,
1888
- cancelable: false
1889
- }
1890
- },
1891
- ended: {
1892
- EventType: "Event",
1893
- defaultInit: {
1894
- bubbles: false,
1895
- cancelable: false
1896
- }
1897
- },
1898
- loadedData: {
1899
- EventType: "Event",
1900
- defaultInit: {
1901
- bubbles: false,
1902
- cancelable: false
1903
- }
1904
- },
1905
- loadedMetadata: {
1906
- EventType: "Event",
1907
- defaultInit: {
1908
- bubbles: false,
1909
- cancelable: false
1910
- }
1911
- },
1912
- loadStart: {
1913
- EventType: "ProgressEvent",
1914
- defaultInit: {
1915
- bubbles: false,
1916
- cancelable: false
1917
- }
1918
- },
1919
- pause: {
1920
- EventType: "Event",
1921
- defaultInit: {
1922
- bubbles: false,
1923
- cancelable: false
1924
- }
1925
- },
1926
- play: {
1927
- EventType: "Event",
1928
- defaultInit: {
1929
- bubbles: false,
1930
- cancelable: false
1931
- }
1932
- },
1933
- playing: {
1934
- EventType: "Event",
1935
- defaultInit: {
1936
- bubbles: false,
1937
- cancelable: false
1938
- }
1939
- },
1940
- progress: {
1941
- EventType: "ProgressEvent",
1942
- defaultInit: {
1943
- bubbles: false,
1944
- cancelable: false
1945
- }
1946
- },
1947
- rateChange: {
1948
- EventType: "Event",
1949
- defaultInit: {
1950
- bubbles: false,
1951
- cancelable: false
1952
- }
1953
- },
1954
- seeked: {
1955
- EventType: "Event",
1956
- defaultInit: {
1957
- bubbles: false,
1958
- cancelable: false
1959
- }
1960
- },
1961
- seeking: {
1962
- EventType: "Event",
1963
- defaultInit: {
1964
- bubbles: false,
1965
- cancelable: false
1966
- }
1967
- },
1968
- stalled: {
1969
- EventType: "Event",
1970
- defaultInit: {
1971
- bubbles: false,
1972
- cancelable: false
1973
- }
1974
- },
1975
- suspend: {
1976
- EventType: "Event",
1977
- defaultInit: {
1978
- bubbles: false,
1979
- cancelable: false
1980
- }
1981
- },
1982
- timeUpdate: {
1983
- EventType: "Event",
1984
- defaultInit: {
1985
- bubbles: false,
1986
- cancelable: false
1987
- }
1988
- },
1989
- volumeChange: {
1990
- EventType: "Event",
1991
- defaultInit: {
1992
- bubbles: false,
1993
- cancelable: false
1994
- }
1995
- },
1996
- waiting: {
1997
- EventType: "Event",
1998
- defaultInit: {
1999
- bubbles: false,
2000
- cancelable: false
2001
- }
2002
- },
2003
- load: {
2004
- EventType: "Event",
2005
- defaultInit: {
2006
- bubbles: false,
2007
- cancelable: false
2008
- }
2009
- },
2010
- error: {
2011
- EventType: "Event",
2012
- defaultInit: {
2013
- bubbles: false,
2014
- cancelable: false
2015
- }
2016
- },
2017
- animationStart: {
2018
- EventType: "AnimationEvent",
2019
- defaultInit: {
2020
- bubbles: true,
2021
- cancelable: false
2022
- }
2023
- },
2024
- animationEnd: {
2025
- EventType: "AnimationEvent",
2026
- defaultInit: {
2027
- bubbles: true,
2028
- cancelable: false
2029
- }
2030
- },
2031
- animationIteration: {
2032
- EventType: "AnimationEvent",
2033
- defaultInit: {
2034
- bubbles: true,
2035
- cancelable: false
2036
- }
2037
- },
2038
- transitionCancel: {
2039
- EventType: "TransitionEvent",
2040
- defaultInit: {
2041
- bubbles: true,
2042
- cancelable: false
2043
- }
2044
- },
2045
- transitionEnd: {
2046
- EventType: "TransitionEvent",
2047
- defaultInit: {
2048
- bubbles: true,
2049
- cancelable: true
2050
- }
2051
- },
2052
- transitionRun: {
2053
- EventType: "TransitionEvent",
2054
- defaultInit: {
2055
- bubbles: true,
2056
- cancelable: false
2057
- }
2058
- },
2059
- transitionStart: {
2060
- EventType: "TransitionEvent",
2061
- defaultInit: {
2062
- bubbles: true,
2063
- cancelable: false
2064
- }
2065
- },
2066
- pointerOver: {
2067
- EventType: "PointerEvent",
2068
- defaultInit: {
2069
- bubbles: true,
2070
- cancelable: true,
2071
- composed: true
2072
- }
2073
- },
2074
- pointerEnter: {
2075
- EventType: "PointerEvent",
2076
- defaultInit: {
2077
- bubbles: false,
2078
- cancelable: false
2079
- }
2080
- },
2081
- pointerDown: {
2082
- EventType: "PointerEvent",
2083
- defaultInit: {
2084
- bubbles: true,
2085
- cancelable: true,
2086
- composed: true
2087
- }
2088
- },
2089
- pointerMove: {
2090
- EventType: "PointerEvent",
2091
- defaultInit: {
2092
- bubbles: true,
2093
- cancelable: true,
2094
- composed: true
2095
- }
2096
- },
2097
- pointerUp: {
2098
- EventType: "PointerEvent",
2099
- defaultInit: {
2100
- bubbles: true,
2101
- cancelable: true,
2102
- composed: true
2103
- }
2104
- },
2105
- pointerCancel: {
2106
- EventType: "PointerEvent",
2107
- defaultInit: {
2108
- bubbles: true,
2109
- cancelable: false,
2110
- composed: true
2111
- }
2112
- },
2113
- pointerOut: {
2114
- EventType: "PointerEvent",
2115
- defaultInit: {
2116
- bubbles: true,
2117
- cancelable: true,
2118
- composed: true
2119
- }
2120
- },
2121
- pointerLeave: {
2122
- EventType: "PointerEvent",
2123
- defaultInit: {
2124
- bubbles: false,
2125
- cancelable: false
2126
- }
2127
- },
2128
- gotPointerCapture: {
2129
- EventType: "PointerEvent",
2130
- defaultInit: {
2131
- bubbles: true,
2132
- cancelable: false,
2133
- composed: true
2134
- }
2135
- },
2136
- lostPointerCapture: {
2137
- EventType: "PointerEvent",
2138
- defaultInit: {
2139
- bubbles: true,
2140
- cancelable: false,
2141
- composed: true
2142
- }
2143
- },
2144
- popState: {
2145
- EventType: "PopStateEvent",
2146
- defaultInit: {
2147
- bubbles: true,
2148
- cancelable: false
2149
- }
2150
- },
2151
- offline: {
2152
- EventType: "Event",
2153
- defaultInit: {
2154
- bubbles: false,
2155
- cancelable: false
2156
- }
2157
- },
2158
- online: {
2159
- EventType: "Event",
2160
- defaultInit: {
2161
- bubbles: false,
2162
- cancelable: false
2163
- }
2164
- },
2165
- pageHide: {
2166
- EventType: "PageTransitionEvent",
2167
- defaultInit: {
2168
- bubbles: true,
2169
- cancelable: true
2170
- }
2171
- },
2172
- pageShow: {
2173
- EventType: "PageTransitionEvent",
2174
- defaultInit: {
2175
- bubbles: true,
2176
- cancelable: true
2177
- }
2178
- }
2179
- };
2180
- const eventAliasMap = { doubleClick: "dblClick" };
2181
-
2182
- // src/events.ts
2183
- function fireEvent_(element, event) {
2184
- if (tracing() && event && element) return traceSync("testing-library.fire_event", `fireEvent.${event.type}(${describeNode(element)})`, () => fireEventUntraced(element, event));
2185
- return fireEventUntraced(element, event);
2186
- }
2187
- function fireEventUntraced(element, event) {
2188
- return getConfig().eventWrapper(() => {
2189
- if (!event) throw new Error(`Unable to fire an event - please provide an event object.`);
2190
- if (!element) throw new Error(`Unable to fire a "${event.type}" event - please provide a DOM element.`);
2191
- return element.dispatchEvent(event);
2192
- });
2193
- }
2194
- function createEvent_(eventName, node, init, { EventType = "Event", defaultInit = {} } = {}) {
2195
- if (!node) throw new Error(`Unable to fire a "${eventName}" event - please provide a DOM element.`);
2196
- const eventInit = {
2197
- ...defaultInit,
2198
- ...init
2199
- };
2200
- const { target: { value, files, ...targetProperties } = {} } = eventInit;
2201
- if (value !== void 0) setNativeValue(node, value);
2202
- if (files !== void 0) Object.defineProperty(node, "files", {
2203
- configurable: true,
2204
- enumerable: true,
2205
- writable: true,
2206
- value: files
2207
- });
2208
- Object.assign(node, targetProperties);
2209
- const window = getWindowFromNode(node);
2210
- const EventConstructor = window[EventType] || window.Event;
2211
- let event;
2212
- if (typeof EventConstructor === "function") event = new EventConstructor(eventName, eventInit);
2213
- else {
2214
- event = window.document.createEvent(EventType);
2215
- const { bubbles, cancelable, detail, ...otherInit } = eventInit;
2216
- event.initEvent(eventName, bubbles, cancelable, detail);
2217
- Object.keys(otherInit).forEach((eventKey) => {
2218
- event[eventKey] = otherInit[eventKey];
2219
- });
2220
- }
2221
- ["dataTransfer", "clipboardData"].forEach((dataTransferKey) => {
2222
- const dataTransferValue = eventInit[dataTransferKey];
2223
- if (typeof dataTransferValue === "object") {
2224
- if (typeof window.DataTransfer === "function") Object.defineProperty(event, dataTransferKey, { value: Object.getOwnPropertyNames(dataTransferValue).reduce((acc, propName) => {
2225
- Object.defineProperty(acc, propName, { value: dataTransferValue[propName] });
2226
- return acc;
2227
- }, new window.DataTransfer()) });
2228
- else Object.defineProperty(event, dataTransferKey, { value: dataTransferValue });
2229
- }
2230
- });
2231
- return event;
2232
- }
2233
- function setNativeValue(element, value) {
2234
- const { set: valueSetter } = Object.getOwnPropertyDescriptor(element, "value") || {};
2235
- const prototype = Object.getPrototypeOf(element);
2236
- const { set: prototypeValueSetter } = Object.getOwnPropertyDescriptor(prototype, "value") || {};
2237
- if (prototypeValueSetter && valueSetter !== prototypeValueSetter) prototypeValueSetter.call(element, value);
2238
- else if (valueSetter) valueSetter.call(element, value);
2239
- else throw new Error("The given element does not have a value setter");
2240
- }
2241
- Object.defineProperty(fireEvent_, "name", { value: "fireEvent" });
2242
- Object.defineProperty(createEvent_, "name", { value: "createEvent" });
2243
- const fireEvent = fireEvent_;
2244
- const createEvent = createEvent_;
2245
- Object.keys(eventMap).forEach((key) => {
2246
- const { EventType, defaultInit } = eventMap[key];
2247
- const eventName = key.toLowerCase();
2248
- createEvent[key] = (node, init) => createEvent(eventName, node, init, {
2249
- EventType,
2250
- defaultInit
2251
- });
2252
- fireEvent[key] = (node, init) => fireEvent(node, createEvent[key](node, init));
2253
- });
2254
- Object.keys(eventAliasMap).forEach((aliasKey) => {
2255
- const key = eventAliasMap[aliasKey];
2256
- fireEvent[aliasKey] = (...args) => fireEvent[key](...args);
2257
- });
13
+ ${e}`,r)}return a[0]||null}}function getSuggestionError(e,t){return f().getElementError(`A better query is available, try this:
14
+ ${e.toString()}
15
+ `,t)}function makeGetAllQuery(e,t){return(n,...r)=>{let i=e(n,...r);if(!i.length)throw f().getElementError(t(n,...r),n);return i}}function makeFindQuery(e,t=`find`){return(n,r,i,a)=>{let find=t=>waitForInSpan(()=>e(n,r,i),{container:n,...a},t);return N()?ie(V,j(t,[r,i]),async e=>{let t=await find(e);return e.data.matches=matchCount(t),t}):find(null)}}const V=`testing-library.query`,matchCount=e=>Array.isArray(e)?e.length:+!!e;function traceQuery(e,t){return(n,...r)=>N()?ae(V,j(e,r),e=>{let i=t(n,...r);return e.data.matches=matchCount(i),i}):t(n,...r)}const wrapSingleQueryWithSuggestion=(e,t,n)=>(r,...i)=>{let a=e(r,...i),[{suggest:o=f().throwSuggestions}={}]=i.slice(-1);if(a&&o){let e=getSuggestedQuery(a,n);if(e&&!t.endsWith(e.queryName))throw getSuggestionError(e.toString(),r)}return a},wrapAllByQueryWithSuggestion=(e,t,n)=>(r,...i)=>{let a=e(r,...i),[{suggest:o=f().throwSuggestions}={}]=i.slice(-1);if(a.length&&o){let e=[...new Set(a.map(e=>getSuggestedQuery(e,n)?.toString()))];if(e.length===1&&!t.endsWith(getSuggestedQuery(a[0],n).queryName))throw getSuggestionError(e[0],r)}return a};function buildQueries(e,t,n){let r=wrapSingleQueryWithSuggestion(makeSingleQuery(e,t),e.name,`query`),i=makeGetAllQuery(e,n),a=makeSingleQuery(i,t),o=wrapSingleQueryWithSuggestion(a,e.name,`get`),s=wrapAllByQueryWithSuggestion(i,e.name.replace(`query`,`get`),`getAll`),c=e.name.startsWith(`queryAll`)?e.name.slice(8):``,l=makeFindQuery(wrapAllByQueryWithSuggestion(i,e.name,`findAll`),`findAll${c}`),u=makeFindQuery(wrapSingleQueryWithSuggestion(a,e.name,`find`),`find${c}`);return[traceQuery(`query${c}`,r),traceQuery(`getAll${c}`,s),traceQuery(`get${c}`,o),l,u]}const H=/* @__PURE__ */ new Set([``,`generic`,`none`,`presentation`]),U=/* @__PURE__ */ a(e=>e,`identity`);function normalize(e){return e.replace(/\s+/g,` `).trim()}function similarity(e,t){let n=normalize(e).toLowerCase(),r=normalize(t).toLowerCase();if(n===``||r===``)return-1;if(n===r)return 0;if(n.includes(r)||r.includes(n))return 1;let i=r.split(` `);for(let e=0;e<i.length;e++)if(i[e].length>2&&n.includes(i[e]))return 2;return-1}function closeness(e,t,n,r,i=!0){if((i?matches$1:fuzzyMatches)(e,t,n,r))return 0;if(typeof n==`string`||typeof n==`number`){let t=similarity(r(e),String(n));return t===-1?-1:t+1}return-1}function line(e,t,n,r,i){let a={role:t,name:n,props:x(e,t,!1,r),value:null,url:null,children:[],element:e};return`- ${c(a,80)} # ${i}`}function format(e,t){if(t.length===0)return``;t.sort((e,t)=>e.rank-t.rank);let n=t.slice(0,10).map(e=>e.line);return t.length>10&&n.push(`# … ${t.length-10} more`),`${e}:\n${n.join(`
16
+ `)}`}function nameOf(e){return normalize(P(e,void 0,5))}function roleCandidates(t,n){let r=e(t),i=[],a=n.name;for(let e=r.first;e!==null;e=M(e,r)){if(e.type!==E)continue;let t=F(e),r=I(e);if(L(e,n.role,n.queryFallbacks)){let o=nameOf(e),s=a===void 0?0:closeness(o,e.node,a,U),c=n.matchesState(e);s===0&&c?t&&!n.hidden&&i.push({line:line(e,r,o,!0,`hidden: ${d(e)} (or pass { hidden: true })`),rank:0}):s===0?i.push({line:line(e,r,o,t&&!n.hidden,`role and name match, state is not ${n.stateHint}`),rank:1}):(!t||n.hidden)&&i.push({line:line(e,r,o,!1,s>0?`similar name`:`same role, other name`),rank:s>0?2+s:10});continue}if(a===void 0)continue;if(!H.has(r)){let o=nameOf(e);if(o===``)continue;let s=closeness(o,e.node,a,U);s>=0&&i.push({line:line(e,r,o,t&&!n.hidden,`same name, role "${r}"`),rank:2+s});continue}let o=normalize(getNodeTextImpl(e));o!==``&&closeness(o,e.node,a,U)===0&&i.push({line:`- text: ${w(C(o,80))} # in ${_(e)}, which has no role: give it role="${n.role}" or use getByText`,rank:2})}return format(`Closest matches`,i)}function roleOrTag(e){let t=I(e);return H.has(t)?_(e):t}function textCandidates(t,n,r,i,a,o){if(typeof n==`function`)return``;let c=e(t),l=[],u=[];for(let e=c.first;e!==null;e=M(e,c)){if(e.type!==E||a&&typeof a==`string`&&s(e,a))continue;let t=getNodeTextImpl(e),c=t.trim()===``?-1:closeness(t,e.node,n,r,o);c===0?l.push({line:`- ${roleOrTag(e)}: ${w(C(r(t),80))} # matches, but not selector "${i}"`,rank:0}):c>0&&l.push({line:`- ${roleOrTag(e)}: ${w(C(r(t),80))} # similar text in ${_(e)}`,rank:1+c}),c!==0&&e.first!==null&&e.first!==e.last&&(o?matches$1:fuzzyMatches)(e.node.textContent,e.node,n,r)&&u.push(e)}for(let e=0;e<u.length;e++){let t=u[e],n=!1;for(let r=e+1;r<u.length&&!n;r++)isAncestor(t,u[r])&&(n=!0);n||l.push({line:`- ${roleOrTag(t)}: ${w(C(r(t.node.textContent),80))} # text split across child elements of ${_(t)}: use a function matcher or getByRole`,rank:0})}return format(`Closest matches`,l)}function isAncestor(e,t){for(let n=t.parent;n!==null;n=n.parent)if(n===e)return!0;return!1}const ye=/* @__PURE__ */ new Set([`textbox`,`searchbox`,`combobox`,`listbox`,`checkbox`,`radio`,`switch`,`slider`,`spinbutton`]);function labelCandidates(t,n,r,i){if(typeof n==`function`)return``;let a=e(t),o=[];for(let e=a.first;e!==null;e=M(e,a)){if(e.type!==E)continue;let t=I(e);if(!ye.has(t))continue;let a=nameOf(e),s=F(e);if(a===``){let i=A(e,`placeholder`),a=i?`no label, placeholder ${w(i)}: use getByPlaceholderText or add a <label>`:`no label: add a <label>, aria-label or aria-labelledby`;o.push({line:line(e,t,``,s,a),rank:i&&closeness(i,e.node,n,r)>=0?1:5});continue}let c=closeness(a,e.node,n,r,i);o.push({line:line(e,t,a,s,c>=0?`similar label`:`labelled control`),rank:c>=0?2+c:10})}return format(`Labelled form controls`,o)}var be=/* @__PURE__ */ i({findAllByLabelText:()=>q,findByLabelText:()=>J,getAllByLabelText:()=>xe,getByLabelText:()=>Se,queryAllByLabelText:()=>Ce,queryByLabelText:()=>G});function queryAllLabels(t){let n=e(t),r=[];for(let e=n.first;e!==null;e=M(e,n)){if(e.type!==E||e.name!==`label`&&e.name!==`input`)continue;let t=getLabelContentImpl(e);t!==null&&r.push({node:e.node,textToMatch:t})}return r}function queryAllLabelsByText(e,t,{exact:n=!0,trim:r,collapseWhitespace:i,normalizer:a}={}){let o=n?matches$1:fuzzyMatches,s=makeNormalizer({collapseWhitespace:i,trim:r,normalizer:a});return queryAllLabels(e).filter(({node:e,textToMatch:n})=>o(n,e,t,s)).map(({node:e})=>e)}function queryAllByLabelText(t,r,{selector:i=`*`,exact:a=!0,collapseWhitespace:o,trim:c,normalizer:l}={}){n(t);let u=a?matches$1:fuzzyMatches,d=makeNormalizer({collapseWhitespace:o,trim:c,normalizer:l}),f=e(t),p=new LabelContext(f),m=[];for(let e=f.first;e!==null;e=M(e,f))e.type===E&&(A(e,`aria-labelledby`)!==null||p.labelsOf(e).length!==0)&&collectLabelled(p,e,i,u,r,d,m);let h=queryAllByAttribute(`aria-label`,t,r,{exact:a,normalizer:d});for(let e=0;e<h.length;e++)m.push(h[e]);let g=Array.from(new Set(m));return i===`*`?g:g.filter(e=>s(e[T],i))}function collectLabelled(e,t,n,r,i,a,o){let s=getLabelsImpl(e,t,n);for(let e of s){if(!e.formControl)continue;let t=e.formControl.node;r(e.content,t,i,a)&&o.push(t)}let c=s.filter(e=>!!e.content).map(e=>e.content),l=t.node;r(c.join(` `),l,i,a)&&o.push(l),c.length>1&&c.forEach((e,t)=>{r(e,l,i,a)&&o.push(l);let n=[...c];n.splice(t,1),n.length>1&&r(n.join(` `),l,i,a)&&o.push(l)})}function getAllByLabelText(e,t,...n){let r=queryAllByLabelText(e,t,...n);if(!r.length){let r=queryAllLabelsByText(e,t,...n);if(r.length){let n=r.map(t=>getTagNameOfElementAssociatedWithLabelViaFor(e,t)).filter(e=>!!e);throw n.length?f().getElementError(n.map(e=>`Found a label with the text of: ${t}, however the element associated with this label (<${e} />) is non-labellable [https://html.spec.whatwg.org/multipage/forms.html#category-label]. If you really need to label a <${e} />, you can use aria-label or aria-labelledby instead.`).join(`
2258
17
 
2259
- // src/lz-string.ts
2260
- const keyStrUriSafe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$";
2261
- var BitWriter = class {
2262
- out = [];
2263
- val = 0;
2264
- pos = 0;
2265
- /** Write the low `n` bits of `value`, least significant bit first. */
2266
- write(value, n) {
2267
- for (let i = 0; i < n; i++) {
2268
- this.val = this.val << 1 | value & 1;
2269
- if (this.pos === 5) {
2270
- this.pos = 0;
2271
- this.out.push(keyStrUriSafe.charAt(this.val));
2272
- this.val = 0;
2273
- } else this.pos++;
2274
- value >>= 1;
2275
- }
2276
- }
2277
- flush() {
2278
- for (;;) {
2279
- this.val <<= 1;
2280
- if (this.pos === 5) {
2281
- this.out.push(keyStrUriSafe.charAt(this.val));
2282
- break;
2283
- }
2284
- this.pos++;
2285
- }
2286
- return this.out.join("");
2287
- }
2288
- };
2289
- function compressToEncodedURIComponent(uncompressed) {
2290
- if (uncompressed == null) return "";
2291
- const dictionary = /* @__PURE__ */ new Map();
2292
- const toCreate = /* @__PURE__ */ new Set();
2293
- const w8 = new BitWriter();
2294
- let w = "";
2295
- let enlargeIn = 2;
2296
- let dictSize = 3;
2297
- let numBits = 2;
2298
- const emit = (word) => {
2299
- if (toCreate.has(word)) {
2300
- const code = word.charCodeAt(0);
2301
- if (code < 256) {
2302
- w8.write(0, numBits);
2303
- w8.write(code, 8);
2304
- } else {
2305
- w8.write(1, numBits);
2306
- w8.write(code, 16);
2307
- }
2308
- enlargeIn--;
2309
- if (enlargeIn === 0) {
2310
- enlargeIn = Math.pow(2, numBits);
2311
- numBits++;
2312
- }
2313
- toCreate.delete(word);
2314
- } else w8.write(dictionary.get(word), numBits);
2315
- enlargeIn--;
2316
- if (enlargeIn === 0) {
2317
- enlargeIn = Math.pow(2, numBits);
2318
- numBits++;
2319
- }
2320
- };
2321
- for (let ii = 0; ii < uncompressed.length; ii++) {
2322
- const c = uncompressed.charAt(ii);
2323
- if (!dictionary.has(c)) {
2324
- dictionary.set(c, dictSize++);
2325
- toCreate.add(c);
2326
- }
2327
- const wc = w + c;
2328
- if (dictionary.has(wc)) w = wc;
2329
- else {
2330
- emit(w);
2331
- dictionary.set(wc, dictSize++);
2332
- w = c;
2333
- }
2334
- }
2335
- if (w !== "") emit(w);
2336
- w8.write(2, numBits);
2337
- return w8.flush();
2338
- }
18
+ `),e):f().getElementError(`Found a label with the text of: ${t}, however no form control was found associated to that label. Make sure you're using the "for" attribute or "aria-labelledby" attribute correctly.`,e)}throw f().getElementError(withLabelCandidates(`Unable to find a label with the text of: ${t}`,e,t,n[0]),e)}return r}function withLabelCandidates(e,t,n,r={}){if(S()===null)return e;let{exact:i=!0,trim:a,collapseWhitespace:o,normalizer:s}=r,c=labelCandidates(t,n,makeNormalizer({trim:a,collapseWhitespace:o,normalizer:s}),i);return c===``?e:`${e}\n\n${c}`}function getTagNameOfElementAssociatedWithLabelViaFor(t,n){let r=n.getAttribute(`for`);if(!r)return null;let i=new LabelContext(e(t)).byIdInContainer(r);return i?i.node.tagName.toLowerCase():null}const W=/* @__PURE__ */ a((e,t)=>`Found multiple elements with the text of: ${t}`,`getMultipleError`),G=wrapSingleQueryWithSuggestion(makeSingleQuery(queryAllByLabelText,W),queryAllByLabelText.name,`query`),K=makeSingleQuery(getAllByLabelText,W),q=makeFindQuery(wrapAllByQueryWithSuggestion(getAllByLabelText,getAllByLabelText.name,`findAll`)),J=makeFindQuery(wrapSingleQueryWithSuggestion(K,getAllByLabelText.name,`find`)),xe=wrapAllByQueryWithSuggestion(getAllByLabelText,getAllByLabelText.name,`getAll`),Se=wrapSingleQueryWithSuggestion(K,getAllByLabelText.name,`get`),Ce=wrapAllByQueryWithSuggestion(queryAllByLabelText,queryAllByLabelText.name,`queryAll`);var we=/* @__PURE__ */ i({findAllByPlaceholderText:()=>je,findByPlaceholderText:()=>Me,getAllByPlaceholderText:()=>ke,getByPlaceholderText:()=>Ae,queryAllByPlaceholderText:()=>De,queryByPlaceholderText:()=>Oe});function queryAllByPlaceholderText(...e){return n(e[0]),queryAllByAttribute(`placeholder`,...e)}const Te=/* @__PURE__ */ a((e,t)=>`Found multiple elements with the placeholder text of: ${t}`,`getMultipleError`),Ee=/* @__PURE__ */ a((e,t)=>`Unable to find an element with the placeholder text of: ${t}`,`getMissingError`),De=wrapAllByQueryWithSuggestion(queryAllByPlaceholderText,queryAllByPlaceholderText.name,`queryAll`),[Oe,ke,Ae,je,Me]=buildQueries(queryAllByPlaceholderText,Te,Ee);var Ne=/* @__PURE__ */ i({findAllByText:()=>Be,findByText:()=>Ve,getAllByText:()=>Re,getByText:()=>ze,queryAllByText:()=>Ie,queryByText:()=>Le});function isScriptStyleIgnore(e){return e===`script, style`||e===`script,style`}function isScriptOrStyle(e){let t=e.name;return t===`script`||t===`style`}function queryAllByText(t,r,{selector:i=`*`,exact:a=!0,collapseWhitespace:o,trim:c,ignore:l=f().defaultIgnore,normalizer:u}={}){n(t);let d=a?matches$1:fuzzyMatches,p=makeNormalizer({collapseWhitespace:o,trim:c,normalizer:u}),m=e(t),h=i===`*`,g=isScriptStyleIgnore(l),_=[],visit=e=>{(h||s(e,i))&&(l&&(g?isScriptOrStyle(e):s(e,l))||d(getNodeTextImpl(e),e.node,r,p)&&_.push(e.node))};m.type===E&&visit(m);for(let e=m.first;e!==null;e=M(e,m))e.type===E&&visit(e);return _}const Pe=/* @__PURE__ */ a((e,t)=>`Found multiple elements with the text: ${t}`,`getMultipleError`),Fe=/* @__PURE__ */ a((e,t,n={})=>{let{collapseWhitespace:r,trim:i,normalizer:a,selector:o}=n,s=makeNormalizer({collapseWhitespace:r,trim:i,normalizer:a}),c=s(t.toString()),l=c!==t.toString(),u=(o??`*`)!==`*`,d=`Unable to find an element with the text: ${l?`${c} (normalized from '${t}')`:t}${u?`, which matches selector '${o}'`:``}. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.`;if(S()===null)return d;let{exact:p=!0,ignore:m=f().defaultIgnore}=n,h=textCandidates(e,t,s,o??`*`,m,p);return h===``?d:`${d}\n\n${h}`},`getMissingError`),Ie=wrapAllByQueryWithSuggestion(queryAllByText,queryAllByText.name,`queryAll`),[Le,Re,ze,Be,Ve]=buildQueries(queryAllByText,Pe,Fe);var He=/* @__PURE__ */ i({findAllByDisplayValue:()=>Ye,findByDisplayValue:()=>Xe,getAllByDisplayValue:()=>qe,getByDisplayValue:()=>Je,queryAllByDisplayValue:()=>Ge,queryByDisplayValue:()=>Ke});function queryAllByDisplayValue(t,r,{exact:i=!0,collapseWhitespace:a,trim:o,normalizer:s}={}){n(t);let c=i?matches$1:fuzzyMatches,l=makeNormalizer({collapseWhitespace:a,trim:o,normalizer:s}),u=e(t),d=[];for(let e=u.first;e!==null;e=M(e,u)){if(e.type!==E)continue;let t=e.name;if(t!==`input`&&t!==`textarea`&&t!==`select`)continue;let n=e.node;if(e.tag===O.select&&e.ns===D){let e=n.options,t=!1;for(let n=0;n<e.length;n++){let i=e[n];if(i.selected&&c(getNodeTextImpl(i[T]),i,r,l)){t=!0;break}}t&&d.push(n)}else c(n.value,n,r,l)&&d.push(n)}return d}const Ue=/* @__PURE__ */ a((e,t)=>`Found multiple elements with the display value: ${t}.`,`getMultipleError`),We=/* @__PURE__ */ a((e,t)=>`Unable to find an element with the display value: ${t}.`,`getMissingError`),Ge=wrapAllByQueryWithSuggestion(queryAllByDisplayValue,queryAllByDisplayValue.name,`queryAll`),[Ke,qe,Je,Ye,Xe]=buildQueries(queryAllByDisplayValue,Ue,We);var Ze=/* @__PURE__ */ i({findAllByAltText:()=>at,findByAltText:()=>ot,getAllByAltText:()=>rt,getByAltText:()=>it,queryAllByAltText:()=>tt,queryByAltText:()=>nt});const Qe=/^(img|input|area|.+-.+)$/i;function queryAllByAltText(e,t,r={}){return n(e),queryAllByAttribute(`alt`,e,t,r).filter(e=>Qe.test(e.tagName))}const $e=/* @__PURE__ */ a((e,t)=>`Found multiple elements with the alt text: ${t}`,`getMultipleError`),et=/* @__PURE__ */ a((e,t)=>`Unable to find an element with the alt text: ${t}`,`getMissingError`),tt=wrapAllByQueryWithSuggestion(queryAllByAltText,queryAllByAltText.name,`queryAll`),[nt,rt,it,at,ot]=buildQueries(queryAllByAltText,$e,et);var st=/* @__PURE__ */ i({findAllByTitle:()=>mt,findByTitle:()=>ht,getAllByTitle:()=>ft,getByTitle:()=>pt,queryAllByTitle:()=>ut,queryByTitle:()=>dt});function isSvgTitle(e){let t=e.parent;return k(e.prefix===null?e.name:e.prefix+`:`+e.name)===`title`&&t!==null&&t.type===E&&k(t.prefix===null?t.name:t.prefix+`:`+t.name)===`svg`}function queryAllByTitle(t,r,{exact:i=!0,collapseWhitespace:a,trim:o,normalizer:s}={}){n(t);let c=i?matches$1:fuzzyMatches,l=makeNormalizer({collapseWhitespace:a,trim:o,normalizer:s}),u=e(t),d=[];for(let e=u.first;e!==null;e=M(e,u)){if(e.type!==E)continue;let t=e.attrs===null?null:A(e,`title`),n=e.name===`title`&&e.parent!==null&&e.parent.type===E&&e.parent.name===`svg`;(t!==null||n)&&(c(t,e.node,r,l)||isSvgTitle(e)&&c(getNodeTextImpl(e),e.node,r,l))&&d.push(e.node)}return d}const ct=/* @__PURE__ */ a((e,t)=>`Found multiple elements with the title: ${t}.`,`getMultipleError`),lt=/* @__PURE__ */ a((e,t)=>`Unable to find an element with the title: ${t}.`,`getMissingError`),ut=wrapAllByQueryWithSuggestion(queryAllByTitle,queryAllByTitle.name,`queryAll`),[dt,ft,pt,mt,ht]=buildQueries(queryAllByTitle,ct,lt);var gt=/* @__PURE__ */ i({findAllByRole:()=>Ct,findByRole:()=>wt,getAllByRole:()=>xt,getByRole:()=>St,queryAllByRole:()=>yt,queryByRole:()=>bt});const identity=e=>e;function assertSupported(e,t){if(!z.roleSupportsProp(e,t))throw Error(`"${t}" is not supported on role "${e}".`)}function queryAllByRole(t,r,{hidden:i=f().defaultHidden,name:a,description:o,queryFallbacks:s=!1,selected:c,busy:l,checked:u,pressed:d,current:p,level:m,expanded:h,value:{now:g,min:_,max:v,text:y}={}}={}){if(n(t),c!==void 0&&assertSupported(r,`aria-selected`),l!==void 0&&assertSupported(r,`aria-busy`),u!==void 0&&assertSupported(r,`aria-checked`),d!==void 0&&assertSupported(r,`aria-pressed`),p!==void 0&&assertSupported(r,`aria-current`),m!==void 0&&r!==`heading`)throw Error(`Role "${r}" cannot have "level" property.`);g!==void 0&&assertSupported(r,`aria-valuenow`),v!==void 0&&assertSupported(r,`aria-valuemax`),_!==void 0&&assertSupported(r,`aria-valuemin`),y!==void 0&&assertSupported(r,`aria-valuetext`),h!==void 0&&assertSupported(r,`aria-expanded`);let b={selected:c,busy:l,checked:u,pressed:d,current:p,level:m,expanded:h,valueNow:g,valueMin:_,valueMax:v,valueText:y},x=f().computedStyleSupportsPseudoElements,S=e(t),C=[],w=styleOverride(S),T=w!==null&&i===!1?/* @__PURE__ */ new Map:null;for(let e=S.first;e!==null;e=M(e,S))e.type===E&&z.roleMatches(e,r,s)&&matchesState(e,b)&&(i===!1&&(w===null?isInaccessibleImpl$1(e):z.isInaccessibleWithStyle(e,w,T))||(a===void 0||matches$1(z.computeAccessibleName(e,x,w),e.node,a,identity))&&(o===void 0||matches$1(z.computeAccessibleDescription(e,x,w),e.node,o,identity))&&C.push(e.node));return C}function matchesState(e,t){if(t.selected!==void 0)return t.selected===computeAriaSelected$1(e);if(t.busy!==void 0)return t.busy===computeAriaBusy$1(e);if(t.checked!==void 0)return t.checked===computeAriaChecked(e);if(t.pressed!==void 0)return t.pressed===computeAriaPressed(e);if(t.current!==void 0)return t.current===computeAriaCurrent$1(e);if(t.expanded!==void 0)return t.expanded===computeAriaExpanded$1(e);if(t.level!==void 0)return t.level===computeHeadingLevelImpl(e);if(t.valueNow!==void 0||t.valueMax!==void 0||t.valueMin!==void 0||t.valueText!==void 0){let n=!0;return t.valueNow!==void 0&&(n&&=t.valueNow===computeAriaValueNow(e)),t.valueMax!==void 0&&(n&&=t.valueMax===computeAriaValueMax(e)),t.valueMin!==void 0&&(n&&=t.valueMin===computeAriaValueMin(e)),t.valueText!==void 0&&(n&&=matches$1(computeAriaValueText(e)??null,e.node,t.valueText,identity)),n}return!0}const getNameHint=e=>{let t=``;return t=e===void 0?``:typeof e==`string`?` and name "${e}"`:` and name \`${e}\``,t},_t=/* @__PURE__ */ a((e,t,{name:n}={})=>`Found multiple elements with the role "${t}"${getNameHint(n)}`,`getMultipleError`),vt=/* @__PURE__ */ a((e,t,n={})=>{let{hidden:r=f().defaultHidden,name:i,description:a}=n;if(S()!==null)return agentMissingError(e,t,n,r);if(f()._disableExpensiveErrorDiagnostics)return`Unable to find role="${t}"${getNameHint(i)}`;let o=``;Array.from(e.children).forEach(e=>{o+=prettyRoles(e,{hidden:r,includeDescription:a!==void 0})});let s;s=o.length===0?r===!1?"There are no accessible roles. But there might be some inaccessible roles. If you wish to access them, then set the `hidden` option to `true`. Learn more about this here: https://testing-library.com/docs/dom-testing-library/api-queries#byrole":`There are no available roles.`:`
19
+ Here are the ${r===!1?`accessible`:`available`} roles:
2339
20
 
2340
- // src/screen.ts
2341
- function unindent(string) {
2342
- return string.replace(/[ \t]*[\n][ \t]*/g, "\n");
2343
- }
2344
- function encode(value) {
2345
- return compressToEncodedURIComponent(unindent(value));
2346
- }
2347
- function getPlaygroundUrl(markup) {
2348
- return `https://testing-playground.com/#markup=${encode(markup)}`;
2349
- }
2350
- const debug = (element, maxLength, options) => Array.isArray(element) ? element.forEach((el) => logDOM(el, maxLength, options)) : logDOM(element, maxLength, options);
2351
- const logTestingPlaygroundURL = (element = getDocument().body) => {
2352
- if (!element || !("innerHTML" in element)) {
2353
- console.log(`The element you're providing isn't a valid DOM element.`);
2354
- return;
2355
- }
2356
- if (!element.innerHTML) {
2357
- console.log(`The provided element doesn't have any children.`);
2358
- return;
2359
- }
2360
- const playgroundUrl = getPlaygroundUrl(element.innerHTML);
2361
- console.log(`Open this URL in your browser\n\n${playgroundUrl}`);
2362
- return playgroundUrl;
2363
- };
2364
- const initialValue = {
2365
- debug,
2366
- logTestingPlaygroundURL,
2367
- ariaSnapshot
2368
- };
2369
- const screen = typeof document !== "undefined" && document.body ? getQueriesForElement(document.body, queries, initialValue) : Object.keys(queries).reduce((helpers, key) => {
2370
- helpers[key] = () => {
2371
- throw new TypeError("For queries bound to document.body a global document has to be available... Learn more: https://testing-library.com/s/screen-global-error");
2372
- };
2373
- return helpers;
2374
- }, initialValue);
21
+ ${o.replace(/\n/g,`
22
+ `).replace(/\n\s\s\n/g,`
2375
23
 
2376
- // src/index.ts
2377
- const queryHelpers = {
2378
- getElementError,
2379
- wrapAllByQueryWithSuggestion,
2380
- wrapSingleQueryWithSuggestion,
2381
- getMultipleElementsFoundError,
2382
- queryAllByAttribute,
2383
- queryByAttribute,
2384
- makeSingleQuery,
2385
- makeGetAllQuery,
2386
- makeFindQuery,
2387
- buildQueries
2388
- };
24
+ `)}
25
+ `.trim();let c=``;c=i===void 0?``:typeof i==`string`?` and name "${i}"`:` and name \`${i}\``;let l=``;return l=a===void 0?``:typeof a==`string`?` and description "${a}"`:` and description \`${a}\``,`
26
+ Unable to find an ${r===!1?`accessible `:``}element with the role "${t}"${c}${l}
2389
27
 
2390
- export { ariaSnapshot, buildQueries, configure, createEvent, diffAriaSnapshots, findAllByAltText, findAllByDisplayValue, findAllByLabelText, findAllByPlaceholderText, findAllByRole, findAllByTestId, findAllByText, findAllByTitle, findByAltText, findByDisplayValue, findByLabelText, findByPlaceholderText, findByRole, findByTestId, findByText, findByTitle, fireEvent, getAllByAltText, getAllByDisplayValue, getAllByLabelTextWithSuggestions as getAllByLabelText, getAllByPlaceholderText, getAllByRole, getAllByTestId, getAllByText, getAllByTitle, getByAltText, getByDisplayValue, getByLabelTextWithSuggestions as getByLabelText, getByPlaceholderText, getByRole, getByTestId, getByText, getByTitle, getConfig, getDefaultNormalizer, getElementError, getMultipleElementsFoundError, getNodeText, getQueriesForElement, getQueriesForElement as within, getRoles, getSuggestedQuery, isInaccessible, logDOM, logRoles, makeFindQuery, makeGetAllQuery, makeSingleQuery, prettyDOM, prettyFormat, queries, queryAllByAltTextWithSuggestions as queryAllByAltText, queryAllByAttribute, queryAllByDisplayValueWithSuggestions as queryAllByDisplayValue, queryAllByLabelTextWithSuggestions as queryAllByLabelText, queryAllByPlaceholderTextWithSuggestions as queryAllByPlaceholderText, queryAllByRoleWithSuggestions as queryAllByRole, queryAllByTestIdWithSuggestions as queryAllByTestId, queryAllByTextWithSuggestions as queryAllByText, queryAllByTitleWithSuggestions as queryAllByTitle, queryByAltText, queryByAttribute, queryByDisplayValue, queryByLabelText, queryByPlaceholderText, queryByRole, queryByTestId, queryByText, queryByTitle, queryHelpers, screen, waitFor, waitForElementToBeRemoved, wrapAllByQueryWithSuggestion, wrapSingleQueryWithSuggestion };
28
+ ${s}`.trim()},`getMissingError`);function agentMissingError(e,t,n,r){let{name:i,description:a,queryFallbacks:o=!1,value:{now:s,min:c,max:l,text:u}={}}=n,{selected:d,busy:f,checked:p,pressed:m,current:h,level:g,expanded:_}=n,v={selected:d,busy:f,checked:p,pressed:m,current:h,level:g,expanded:_,valueNow:s,valueMin:c,valueMax:l,valueText:u},y=Object.entries({selected:d,busy:f,checked:p,pressed:m,current:h,level:g,expanded:_,value:n.value}).filter(([,e])=>e!==void 0).map(([e,t])=>`${e}: ${JSON.stringify(t)}`).join(`, `),b=a===void 0?``:typeof a==`string`?` and description "${a}"`:` and description \`${a}\``,x=`Unable to find an ${r===!1?`accessible `:``}element with the role "${t}"${getNameHint(i)}${b}`,S=roleCandidates(e,{role:String(t),name:i,hidden:r,queryFallbacks:o,matchesState:e=>matchesState(e,v),stateHint:`{ ${y} }`});return S===``?x:`${x}\n\n${S}`}const yt=wrapAllByQueryWithSuggestion(queryAllByRole,queryAllByRole.name,`queryAll`),[bt,xt,St,Ct,wt]=buildQueries(queryAllByRole,_t,vt);var Tt=/* @__PURE__ */ i({findAllByTestId:()=>At,findByTestId:()=>Y,getAllByTestId:()=>Ot,getByTestId:()=>kt,queryAllByTestId:()=>Et,queryByTestId:()=>Dt});const getTestIdAttribute=()=>f().testIdAttribute;function queryAllByTestId(...e){return n(e[0]),queryAllByAttribute(getTestIdAttribute(),...e)}const getMultipleError=(e,t)=>`Found multiple elements by: [${getTestIdAttribute()}="${t}"]`,getMissingError=(e,t)=>`Unable to find an element by: [${getTestIdAttribute()}="${t}"]`,Et=wrapAllByQueryWithSuggestion(queryAllByTestId,queryAllByTestId.name,`queryAll`),[Dt,Ot,kt,At,Y]=buildQueries(queryAllByTestId,getMultipleError,getMissingError);function build(){let e={},t=[[be,`LabelText`],[we,`PlaceholderText`],[Ne,`Text`],[He,`DisplayValue`],[Ze,`AltText`],[st,`Title`],[gt,`Role`],[Tt,`TestId`]];for(let[n,r]of t)for(let t of[`findAllBy`,`findBy`,`getAllBy`,`getBy`,`queryAllBy`,`queryBy`])e[t+r]=n[t+r];return e}const X=build();function getQueriesForElement(e,t=X,n={}){return Object.keys(t).reduce((n,r)=>(n[r]=t[r].bind(null,e),n),n)}const isRemoved=e=>!e||Array.isArray(e)&&!e.length;function initialCheck(e){if(isRemoved(e))throw Error(`The element(s) given to waitForElementToBeRemoved are already removed. waitForElementToBeRemoved requires that the element(s) exist(s) before waiting for removal.`)}async function waitForElementToBeRemoved(callback,e){let t=/* @__PURE__ */ Error(`Timed out in waitForElementToBeRemoved.`);if(typeof callback!=`function`){initialCheck(callback);let e=(Array.isArray(callback)?callback:[callback]).map(e=>{let t=e.parentElement;if(t===null)return()=>null;for(;t.parentElement;)t=t.parentElement;return()=>t.contains(e)?e:null});callback=()=>e.map(e=>e()).filter(Boolean)}let n=callback;return initialCheck(n()),waitFor(()=>{let e;try{e=n()}catch(e){if(e.name===`TestingLibraryElementError`)return;throw e}if(!isRemoved(e))throw t},e)}const jt={copy:{EventType:`ClipboardEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},cut:{EventType:`ClipboardEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},paste:{EventType:`ClipboardEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},compositionEnd:{EventType:`CompositionEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},compositionStart:{EventType:`CompositionEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},compositionUpdate:{EventType:`CompositionEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},keyDown:{EventType:`KeyboardEvent`,defaultInit:{bubbles:!0,cancelable:!0,charCode:0,composed:!0}},keyPress:{EventType:`KeyboardEvent`,defaultInit:{bubbles:!0,cancelable:!0,charCode:0,composed:!0}},keyUp:{EventType:`KeyboardEvent`,defaultInit:{bubbles:!0,cancelable:!0,charCode:0,composed:!0}},focus:{EventType:`FocusEvent`,defaultInit:{bubbles:!1,cancelable:!1,composed:!0}},blur:{EventType:`FocusEvent`,defaultInit:{bubbles:!1,cancelable:!1,composed:!0}},focusIn:{EventType:`FocusEvent`,defaultInit:{bubbles:!0,cancelable:!1,composed:!0}},focusOut:{EventType:`FocusEvent`,defaultInit:{bubbles:!0,cancelable:!1,composed:!0}},change:{EventType:`Event`,defaultInit:{bubbles:!0,cancelable:!1}},input:{EventType:`InputEvent`,defaultInit:{bubbles:!0,cancelable:!1,composed:!0}},invalid:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!0}},submit:{EventType:`Event`,defaultInit:{bubbles:!0,cancelable:!0}},reset:{EventType:`Event`,defaultInit:{bubbles:!0,cancelable:!0}},click:{EventType:`MouseEvent`,defaultInit:{bubbles:!0,cancelable:!0,button:0,composed:!0}},contextMenu:{EventType:`MouseEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},dblClick:{EventType:`MouseEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},drag:{EventType:`DragEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},dragEnd:{EventType:`DragEvent`,defaultInit:{bubbles:!0,cancelable:!1,composed:!0}},dragEnter:{EventType:`DragEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},dragExit:{EventType:`DragEvent`,defaultInit:{bubbles:!0,cancelable:!1,composed:!0}},dragLeave:{EventType:`DragEvent`,defaultInit:{bubbles:!0,cancelable:!1,composed:!0}},dragOver:{EventType:`DragEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},dragStart:{EventType:`DragEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},drop:{EventType:`DragEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},mouseDown:{EventType:`MouseEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},mouseEnter:{EventType:`MouseEvent`,defaultInit:{bubbles:!1,cancelable:!1,composed:!0}},mouseLeave:{EventType:`MouseEvent`,defaultInit:{bubbles:!1,cancelable:!1,composed:!0}},mouseMove:{EventType:`MouseEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},mouseOut:{EventType:`MouseEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},mouseOver:{EventType:`MouseEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},mouseUp:{EventType:`MouseEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},select:{EventType:`Event`,defaultInit:{bubbles:!0,cancelable:!1}},touchCancel:{EventType:`TouchEvent`,defaultInit:{bubbles:!0,cancelable:!1,composed:!0}},touchEnd:{EventType:`TouchEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},touchMove:{EventType:`TouchEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},touchStart:{EventType:`TouchEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},resize:{EventType:`UIEvent`,defaultInit:{bubbles:!1,cancelable:!1}},scroll:{EventType:`UIEvent`,defaultInit:{bubbles:!1,cancelable:!1}},wheel:{EventType:`WheelEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},abort:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},canPlay:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},canPlayThrough:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},durationChange:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},emptied:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},encrypted:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},ended:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},loadedData:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},loadedMetadata:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},loadStart:{EventType:`ProgressEvent`,defaultInit:{bubbles:!1,cancelable:!1}},pause:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},play:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},playing:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},progress:{EventType:`ProgressEvent`,defaultInit:{bubbles:!1,cancelable:!1}},rateChange:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},seeked:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},seeking:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},stalled:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},suspend:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},timeUpdate:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},volumeChange:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},waiting:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},load:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},error:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},animationStart:{EventType:`AnimationEvent`,defaultInit:{bubbles:!0,cancelable:!1}},animationEnd:{EventType:`AnimationEvent`,defaultInit:{bubbles:!0,cancelable:!1}},animationIteration:{EventType:`AnimationEvent`,defaultInit:{bubbles:!0,cancelable:!1}},transitionCancel:{EventType:`TransitionEvent`,defaultInit:{bubbles:!0,cancelable:!1}},transitionEnd:{EventType:`TransitionEvent`,defaultInit:{bubbles:!0,cancelable:!0}},transitionRun:{EventType:`TransitionEvent`,defaultInit:{bubbles:!0,cancelable:!1}},transitionStart:{EventType:`TransitionEvent`,defaultInit:{bubbles:!0,cancelable:!1}},pointerOver:{EventType:`PointerEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},pointerEnter:{EventType:`PointerEvent`,defaultInit:{bubbles:!1,cancelable:!1}},pointerDown:{EventType:`PointerEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},pointerMove:{EventType:`PointerEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},pointerUp:{EventType:`PointerEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},pointerCancel:{EventType:`PointerEvent`,defaultInit:{bubbles:!0,cancelable:!1,composed:!0}},pointerOut:{EventType:`PointerEvent`,defaultInit:{bubbles:!0,cancelable:!0,composed:!0}},pointerLeave:{EventType:`PointerEvent`,defaultInit:{bubbles:!1,cancelable:!1}},gotPointerCapture:{EventType:`PointerEvent`,defaultInit:{bubbles:!0,cancelable:!1,composed:!0}},lostPointerCapture:{EventType:`PointerEvent`,defaultInit:{bubbles:!0,cancelable:!1,composed:!0}},popState:{EventType:`PopStateEvent`,defaultInit:{bubbles:!0,cancelable:!1}},offline:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},online:{EventType:`Event`,defaultInit:{bubbles:!1,cancelable:!1}},pageHide:{EventType:`PageTransitionEvent`,defaultInit:{bubbles:!0,cancelable:!0}},pageShow:{EventType:`PageTransitionEvent`,defaultInit:{bubbles:!0,cancelable:!0}}},Mt={doubleClick:`dblClick`};function fireEvent_(e,t){return N()&&t&&e?ae(`testing-library.fire_event`,`fireEvent.${t.type}(${ne(e)})`,()=>fireEventUntraced(e,t)):fireEventUntraced(e,t)}function fireEventUntraced(e,t){return f().eventWrapper(()=>{if(!t)throw Error(`Unable to fire an event - please provide an event object.`);if(!e)throw Error(`Unable to fire a "${t.type}" event - please provide a DOM element.`);return e.dispatchEvent(t)})}function createEvent_(e,t,n,{EventType:r=`Event`,defaultInit:i={}}={}){if(!t)throw Error(`Unable to fire a "${e}" event - please provide a DOM element.`);let a={...i,...n},{target:{value:o,files:s,...c}={}}=a;o!==void 0&&setNativeValue(t,o),s!==void 0&&Object.defineProperty(t,"files",{configurable:!0,enumerable:!0,writable:!0,value:s}),Object.assign(t,c);let l=m(t),u=l[r]||l.Event,d;if(typeof u==`function`)d=new u(e,a);else{d=l.document.createEvent(r);let{bubbles:t,cancelable:n,detail:i,...o}=a;d.initEvent(e,t,n,i),Object.keys(o).forEach(e=>{d[e]=o[e]})}return[`dataTransfer`,`clipboardData`].forEach(e=>{let t=a[e];typeof t==`object`&&(typeof l.DataTransfer==`function`?Object.defineProperty(d,e,{value:Object.getOwnPropertyNames(t).reduce((e,n)=>(Object.defineProperty(e,n,{value:t[n]}),e),new l.DataTransfer)}):Object.defineProperty(d,e,{value:t}))}),d}function setNativeValue(e,t){let{set:n}=Object.getOwnPropertyDescriptor(e,`value`)||{},r=Object.getPrototypeOf(e),{set:i}=Object.getOwnPropertyDescriptor(r,`value`)||{};if(i&&n!==i)i.call(e,t);else if(n)n.call(e,t);else throw Error(`The given element does not have a value setter`)}Object.defineProperty(fireEvent_,"name",{value:`fireEvent`}),Object.defineProperty(createEvent_,"name",{value:`createEvent`});const Z=fireEvent_,Q=createEvent_;Object.keys(jt).forEach(e=>{let{EventType:t,defaultInit:n}=jt[e],r=e.toLowerCase();Q[e]=(e,i)=>Q(r,e,i,{EventType:t,defaultInit:n}),Z[e]=(t,n)=>Z(t,Q[e](t,n))}),Object.keys(Mt).forEach(e=>{let t=Mt[e];Z[e]=(...e)=>Z[t](...e)});const Nt=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$`;var BitWriter=class{out=[];val=0;pos=0;write(e,t){for(let n=0;n<t;n++)this.val=this.val<<1|e&1,this.pos===5?(this.pos=0,this.out.push(Nt.charAt(this.val)),this.val=0):this.pos++,e>>=1}flush(){for(;;){if(this.val<<=1,this.pos===5){this.out.push(Nt.charAt(this.val));break}this.pos++}return this.out.join(``)}};function compressToEncodedURIComponent(e){if(e==null)return``;let t=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Set,r=new BitWriter,i=``,a=2,o=3,s=2,emit=e=>{if(n.has(e)){let t=e.charCodeAt(0);t<256?(r.write(0,s),r.write(t,8)):(r.write(1,s),r.write(t,16)),a--,a===0&&(a=2**s,s++),n.delete(e)}else r.write(t.get(e),s);a--,a===0&&(a=2**s,s++)};for(let r=0;r<e.length;r++){let a=e.charAt(r);t.has(a)||(t.set(a,o++),n.add(a));let s=i+a;t.has(s)?i=s:(emit(i),t.set(s,o++),i=a)}return i!==``&&emit(i),r.write(2,s),r.flush()}function unindent(e){return e.replace(/[ \t]*[\n][ \t]*/g,`
29
+ `)}function encode(e){return compressToEncodedURIComponent(unindent(e))}function getPlaygroundUrl(e){return`https://testing-playground.com/#markup=${encode(e)}`}const debug=(e,t,n)=>Array.isArray(e)?e.forEach(e=>g(e,t,n)):g(e,t,n),logTestingPlaygroundURL=(e=o().body)=>{if(!e||!(`innerHTML`in e)){console.log(`The element you're providing isn't a valid DOM element.`);return}if(!e.innerHTML){console.log(`The provided element doesn't have any children.`);return}let t=getPlaygroundUrl(e.innerHTML);return console.log(`Open this URL in your browser\n\n${t}`),t},$={debug,logTestingPlaygroundURL,ariaSnapshot:h},Pt=typeof document<`u`&&document.body?getQueriesForElement(document.body,X,$):Object.keys(X).reduce((e,t)=>(e[t]=()=>{throw TypeError(`For queries bound to document.body a global document has to be available... Learn more: https://testing-library.com/s/screen-global-error`)},e),$),Ft={getElementError,wrapAllByQueryWithSuggestion,wrapSingleQueryWithSuggestion,getMultipleElementsFoundError,queryAllByAttribute,queryByAttribute,makeSingleQuery,makeGetAllQuery,makeFindQuery,buildQueries};export{h as ariaSnapshot,buildQueries,v as configure,Q as createEvent,b as diffAriaSnapshots,at as findAllByAltText,Ye as findAllByDisplayValue,q as findAllByLabelText,je as findAllByPlaceholderText,Ct as findAllByRole,At as findAllByTestId,Be as findAllByText,mt as findAllByTitle,ot as findByAltText,Xe as findByDisplayValue,J as findByLabelText,Me as findByPlaceholderText,wt as findByRole,Y as findByTestId,Ve as findByText,ht as findByTitle,Z as fireEvent,rt as getAllByAltText,qe as getAllByDisplayValue,xe as getAllByLabelText,ke as getAllByPlaceholderText,xt as getAllByRole,Ot as getAllByTestId,Re as getAllByText,ft as getAllByTitle,it as getByAltText,Je as getByDisplayValue,Se as getByLabelText,Ae as getByPlaceholderText,St as getByRole,kt as getByTestId,ze as getByText,pt as getByTitle,f as getConfig,getDefaultNormalizer,getElementError,getMultipleElementsFoundError,getNodeText,getQueriesForElement,getQueriesForElement as within,getRoles,getSuggestedQuery,isInaccessible,g as logDOM,logRoles,makeFindQuery,makeGetAllQuery,makeSingleQuery,y as prettyDOM,u as prettyFormat,X as queries,tt as queryAllByAltText,queryAllByAttribute,Ge as queryAllByDisplayValue,Ce as queryAllByLabelText,De as queryAllByPlaceholderText,yt as queryAllByRole,Et as queryAllByTestId,Ie as queryAllByText,ut as queryAllByTitle,nt as queryByAltText,queryByAttribute,Ke as queryByDisplayValue,G as queryByLabelText,Oe as queryByPlaceholderText,bt as queryByRole,Dt as queryByTestId,Le as queryByText,dt as queryByTitle,Ft as queryHelpers,Pt as screen,waitFor,waitForElementToBeRemoved,wrapAllByQueryWithSuggestion,wrapSingleQueryWithSuggestion};