Skip to content

Commit 6418536

Browse files
afontcuKent C. Dodds
authored andcommitted
fix: value-less element selectors (#319)
1 parent 1e31055 commit 6418536

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/__tests__/__snapshots__/role-helpers.js.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ exports[`logRoles calls console.log with output from prettyRoles 1`] = `
77
data-testid="a-section"
88
/>
99
10+
--------------------------------------------------
11+
link:
12+
13+
<a
14+
data-testid="a-link"
15+
href="http://whatever.com"
16+
/>
17+
1018
--------------------------------------------------
1119
navigation:
1220

src/__tests__/role-helpers.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ afterEach(cleanup)
66
function setup() {
77
const {getByTestId} = render(`
88
<section data-testid='a-section'>
9+
<a href="http://whatever.com" data-testid="a-link">link</a>
10+
<a>invalid link</a>
11+
912
<nav data-testid='a-nav' />
1013
1114
<h1 data-testid='a-h1'>Main Heading</h1>
@@ -54,6 +57,7 @@ function setup() {
5457

5558
return {
5659
section: getByTestId('a-section'),
60+
anchor: getByTestId('a-link'),
5761
h1: getByTestId('a-h1'),
5862
h2: getByTestId('a-h2'),
5963
h3: getByTestId('a-h3'),
@@ -85,6 +89,7 @@ function setup() {
8589
test('getRoles returns expected roles for various dom nodes', () => {
8690
const {
8791
section,
92+
anchor,
8893
h1,
8994
h2,
9095
h3,
@@ -113,6 +118,7 @@ test('getRoles returns expected roles for various dom nodes', () => {
113118
} = setup()
114119

115120
expect(getRoles(section)).toEqual({
121+
link: [anchor],
116122
region: [section],
117123
heading: [h1, h2, h3],
118124
navigation: [nav],

src/role-helpers.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ function getImplicitAriaRoles(currentNode) {
1616
function buildElementRoleList(elementRolesMap) {
1717
function makeElementSelector({name, attributes = []}) {
1818
return `${name}${attributes
19-
.map(({name: attributeName, value}) => `[${attributeName}=${value}]`)
19+
.map(({name: attributeName, value}) =>
20+
value ? `[${attributeName}=${value}]` : `[${attributeName}]`,
21+
)
2022
.join('')}`
2123
}
2224

0 commit comments

Comments
 (0)