Skip to content

Commit 7b3ca97

Browse files
authored
fix: Exclude container in the list of queryable roles (#550)
1 parent 9d62141 commit 7b3ca97

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/__tests__/role.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,28 @@ Here are the accessible roles:
321321
`)
322322
})
323323

324+
test('does not include the container in the queryable roles', () => {
325+
const {getByRole} = render(`<li />`, {
326+
container: document.createElement('ul'),
327+
})
328+
expect(() => getByRole('list')).toThrowErrorMatchingInlineSnapshot(`
329+
"Unable to find an accessible element with the role "list"
330+
331+
Here are the accessible roles:
332+
333+
listitem:
334+
335+
Name "":
336+
<li />
337+
338+
--------------------------------------------------
339+
340+
<ul>
341+
<li />
342+
</ul>"
343+
`)
344+
})
345+
324346
describe('configuration', () => {
325347
let originalConfig
326348
beforeEach(() => {

src/queries/role.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,12 @@ const getMissingError = (
9595
role,
9696
{hidden = getConfig().defaultHidden, name} = {},
9797
) => {
98-
const roles = prettyRoles(container, {
99-
hidden,
100-
includeName: name !== undefined,
98+
let roles = ''
99+
Array.from(container.children).forEach(childElement => {
100+
roles += prettyRoles(childElement, {
101+
hidden,
102+
includeName: name !== undefined,
103+
})
101104
})
102105
let roleMessage
103106

0 commit comments

Comments
 (0)