Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/__tests__/__snapshots__/role-helpers.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ exports[`logRoles calls console.log with output from prettyRoles 1`] = `
data-testid="a-section"
/>

--------------------------------------------------
link:

<a
data-testid="a-link"
href="http://whatever.com"
/>

--------------------------------------------------
navigation:

Expand Down
6 changes: 6 additions & 0 deletions src/__tests__/role-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ afterEach(cleanup)
function setup() {
const {getByTestId} = render(`
<section data-testid='a-section'>
<a href="http://whatever.com" data-testid="a-link">link</a>
<a>invalid link</a>

<nav data-testid='a-nav' />

<h1 data-testid='a-h1'>Main Heading</h1>
Expand Down Expand Up @@ -54,6 +57,7 @@ function setup() {

return {
section: getByTestId('a-section'),
anchor: getByTestId('a-link'),
h1: getByTestId('a-h1'),
h2: getByTestId('a-h2'),
h3: getByTestId('a-h3'),
Expand Down Expand Up @@ -85,6 +89,7 @@ function setup() {
test('getRoles returns expected roles for various dom nodes', () => {
const {
section,
anchor,
h1,
h2,
h3,
Expand Down Expand Up @@ -113,6 +118,7 @@ test('getRoles returns expected roles for various dom nodes', () => {
} = setup()

expect(getRoles(section)).toEqual({
link: [anchor],
region: [section],
heading: [h1, h2, h3],
navigation: [nav],
Expand Down
4 changes: 3 additions & 1 deletion src/role-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ function getImplicitAriaRoles(currentNode) {
function buildElementRoleList(elementRolesMap) {
function makeElementSelector({name, attributes = []}) {
return `${name}${attributes
.map(({name: attributeName, value}) => `[${attributeName}=${value}]`)
.map(({name: attributeName, value}) =>
value ? `[${attributeName}=${value}]` : `[${attributeName}]`,
)
.join('')}`
}

Expand Down