Skip to content

Commit cc8c55b

Browse files
test(ByRole): when hidden, logs elements with their names
1 parent de7ae44 commit cc8c55b

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/__tests__/role.js

+49
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,55 @@ test('when hidden: true logs available roles when it fails', () => {
5353
`)
5454
})
5555

56+
test('when hidden: logs elements with their names when it fails', () => {
57+
const {getByRole} = render(
58+
`<div><h1 hidden>Hi</h1><div hidden role="alertdialog" aria-label="My Dialog">Hello</div></div>`,
59+
)
60+
expect(() => getByRole('article', {hidden: true}))
61+
.toThrowErrorMatchingInlineSnapshot(`
62+
Unable to find an element with the role "article"
63+
64+
Here are the available roles:
65+
66+
heading:
67+
68+
Name "Hi":
69+
<h1
70+
hidden=""
71+
/>
72+
73+
--------------------------------------------------
74+
alertdialog:
75+
76+
Name "My Dialog":
77+
<div
78+
aria-label="My Dialog"
79+
hidden=""
80+
role="alertdialog"
81+
/>
82+
83+
--------------------------------------------------
84+
85+
Ignored nodes: comments, script, style
86+
<div>
87+
<div>
88+
<h1
89+
hidden=""
90+
>
91+
Hi
92+
</h1>
93+
<div
94+
aria-label="My Dialog"
95+
hidden=""
96+
role="alertdialog"
97+
>
98+
Hello
99+
</div>
100+
</div>
101+
</div>
102+
`)
103+
})
104+
56105
test('logs error when there are no accessible roles', () => {
57106
const {getByRole} = render('<div />')
58107
expect(() => getByRole('article')).toThrowErrorMatchingInlineSnapshot(`

0 commit comments

Comments
 (0)