Skip to content

Commit 845cc55

Browse files
test(ByRole): filter by name or description when hidden
1 parent 2a9ee25 commit 845cc55

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

src/__tests__/role.js

+66
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,44 @@ test('can be filtered by accessible name', () => {
233233
).not.toBeNull()
234234
})
235235

236+
test('when hidden can be filtered by accessible name', () => {
237+
const {getByRole} = renderIntoDocument(
238+
`
239+
<div>
240+
<h1>Order</h1>
241+
<h2>Delivery Adress</h2>
242+
<form aria-label="Delivery Adress" aria-hidden="true">
243+
<label>
244+
<div>Street</div>
245+
<input type="text" />
246+
</label>
247+
<input type="submit" />
248+
</form>
249+
<h2>Invoice Adress</h2>
250+
<form aria-label="Invoice Adress">
251+
<label>
252+
<div>Street</div>
253+
<input type="text" />
254+
</label>
255+
<input type="submit" />
256+
</form>
257+
</div>`,
258+
)
259+
260+
const deliveryForm = getByRole('form', {
261+
name: 'Delivery Adress',
262+
hidden: true,
263+
})
264+
expect(deliveryForm).not.toBeNull()
265+
266+
expect(
267+
getQueriesForElement(deliveryForm).getByRole('button', {
268+
name: 'Submit',
269+
hidden: true,
270+
}),
271+
).not.toBeNull()
272+
})
273+
236274
test('accessible name comparison is case sensitive', () => {
237275
const {getByRole} = render(`<h1>Sign <em>up</em></h1>`)
238276

@@ -609,6 +647,34 @@ test('can be filtered by accessible description', () => {
609647
).not.toBeNull()
610648
})
611649

650+
test('when hidden can be filtered by accessible description', () => {
651+
const targetedNotificationMessage = 'Your session is about to expire!'
652+
const {getByRole} = renderIntoDocument(
653+
`
654+
<ul>
655+
<li role="alertdialog" aria-hidden="true" aria-describedby="notification-id-2">
656+
<div><button>Close</button></div>
657+
<div id="notification-id-2">${targetedNotificationMessage}</div>
658+
</li>
659+
</ul>`,
660+
)
661+
662+
const notification = getByRole('alertdialog', {
663+
description: targetedNotificationMessage,
664+
hidden: true,
665+
})
666+
667+
expect(notification).not.toBeNull()
668+
expect(notification).toHaveTextContent(targetedNotificationMessage)
669+
670+
expect(
671+
getQueriesForElement(notification).getByRole('button', {
672+
name: 'Close',
673+
hidden: true,
674+
}),
675+
).not.toBeNull()
676+
})
677+
612678
test('error should include description when filtering and no results are found', () => {
613679
const targetedNotificationMessage = 'Your session is about to expire!'
614680
const {getByRole} = renderIntoDocument(

0 commit comments

Comments
 (0)