You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"Unable to find an element with the role "LucyRicardo"
89
+
"Unable to find an accessible element with the role "LucyRicardo"
90
90
91
-
There are no available roles.
91
+
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
"Unable to find an accessible element with the role "article"
54
+
55
+
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
56
+
57
+
<div>
58
+
<div />
59
+
</div>"
60
+
`)
61
+
})
62
+
63
+
test('logs a different error if inaccessible roles should be included',()=>{
64
+
const{getByRole}=render('<div />')
65
+
expect(()=>getByRole('article',{hidden: true}))
66
+
.toThrowErrorMatchingInlineSnapshot(`
27
67
"Unable to find an element with the role "article"
28
68
29
69
There are no available roles.
@@ -33,3 +73,109 @@ There are no available roles.
33
73
</div>"
34
74
`)
35
75
})
76
+
77
+
test('by default excludes elements that have the html hidden attribute or any of their parents',()=>{
"Unable to find an accessible element with the role "list"
82
+
83
+
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
84
+
85
+
<div>
86
+
<div
87
+
hidden=""
88
+
>
89
+
<ul />
90
+
</div>
91
+
</div>"
92
+
`)
93
+
})
94
+
95
+
test('by default excludes elements which have display: none or any of their parents',()=>{
"Unable to find an accessible element with the role "list"
102
+
103
+
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
104
+
105
+
<div>
106
+
<div
107
+
style="display: none;"
108
+
>
109
+
<ul
110
+
style="display: block;"
111
+
/>
112
+
</div>
113
+
</div>"
114
+
`)
115
+
})
116
+
117
+
test('by default excludes elements which have visibility hidden',()=>{
"Unable to find an accessible element with the role "list"
122
+
123
+
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
124
+
125
+
<div>
126
+
<div
127
+
style="visibility: hidden;"
128
+
>
129
+
<ul />
130
+
</div>
131
+
</div>"
132
+
`)
133
+
})
134
+
135
+
test('by default excludes elements which have aria-hidden="true" or any of their parents',()=>{
136
+
// > if it, or any of its ancestors [...] have their aria-hidden attribute value set to true.
137
+
// -- https://www.w3.org/TR/wai-aria/#aria-hidden
138
+
// > In other words, aria-hidden="true" on a parent overrides aria-hidden="false" on descendants.
"Unable to find an accessible element with the role "list"
146
+
147
+
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
148
+
149
+
<div>
150
+
<div
151
+
aria-hidden="true"
152
+
>
153
+
<ul
154
+
aria-hidden="false"
155
+
/>
156
+
</div>
157
+
</div>"
158
+
`)
159
+
})
160
+
161
+
test('considers the computed visibility style not the parent',()=>{
162
+
// this behavior deviates from the spec which includes "any descendant"
163
+
// if visibility is hidden. However, chrome a11y tree and nvda will include
164
+
// the following markup. This behavior might change depending on how
165
+
// https://github.com/w3c/aria/issues/1055 is resolved.
0 commit comments