Skip to content

Commit

Permalink
fix: Exclude container in the list of queryable roles (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed May 6, 2020
1 parent 9d62141 commit 7b3ca97
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
22 changes: 22 additions & 0 deletions src/__tests__/role.js
Expand Up @@ -321,6 +321,28 @@ Here are the accessible roles:
`)
})

test('does not include the container in the queryable roles', () => {
const {getByRole} = render(`<li />`, {
container: document.createElement('ul'),
})
expect(() => getByRole('list')).toThrowErrorMatchingInlineSnapshot(`
"Unable to find an accessible element with the role "list"
Here are the accessible roles:
listitem:
Name "":
<li />
--------------------------------------------------
<ul>
<li />
</ul>"
`)
})

describe('configuration', () => {
let originalConfig
beforeEach(() => {
Expand Down
9 changes: 6 additions & 3 deletions src/queries/role.js
Expand Up @@ -95,9 +95,12 @@ const getMissingError = (
role,
{hidden = getConfig().defaultHidden, name} = {},
) => {
const roles = prettyRoles(container, {
hidden,
includeName: name !== undefined,
let roles = ''
Array.from(container.children).forEach(childElement => {
roles += prettyRoles(childElement, {
hidden,
includeName: name !== undefined,
})
})
let roleMessage

Expand Down

0 comments on commit 7b3ca97

Please sign in to comment.