@@ -16,7 +16,7 @@ afterEach(() => {
16
16
17
17
function setup ( ) {
18
18
const { getByTestId} = render ( `
19
- <section data-testid='a -section'>
19
+ <section aria-label="a region" data-testid='named -section'>
20
20
<a href="http://whatever.com" data-testid="a-link">link</a>
21
21
<a>invalid link</a>
22
22
@@ -50,7 +50,7 @@ function setup() {
50
50
</tbody>
51
51
</table>
52
52
53
- <form data-testid='a -form'>
53
+ <form aria-label="a form" data-testid='named -form'>
54
54
<input type='radio' data-testid='a-radio-1' />
55
55
<input type='radio' data-testid='a-radio-2' />
56
56
<input type='text' data-testid='a-input-1' />
@@ -62,12 +62,16 @@ function setup() {
62
62
<li data-testid='b-list-item-1'>Item 1</li>
63
63
<li data-testid='b-list-item-2'>Item 2</li>
64
64
</ul>
65
+
66
+ <form data-testid="a-form" />
67
+ <section data-testid="a-section" />
65
68
</article>
66
69
</section>
67
70
` )
68
71
69
72
return {
70
- section : getByTestId ( 'a-section' ) ,
73
+ unnamedSection : getByTestId ( 'a-section' ) ,
74
+ namedSection : getByTestId ( 'named-section' ) ,
71
75
anchor : getByTestId ( 'a-link' ) ,
72
76
h1 : getByTestId ( 'a-h1' ) ,
73
77
h2 : getByTestId ( 'a-h2' ) ,
@@ -88,7 +92,8 @@ function setup() {
88
92
td1 : getByTestId ( 'a-cell-1' ) ,
89
93
td2 : getByTestId ( 'a-cell-2' ) ,
90
94
td3 : getByTestId ( 'a-cell-3' ) ,
91
- form : getByTestId ( 'a-form' ) ,
95
+ unnamedForm : getByTestId ( 'a-form' ) ,
96
+ namedForm : getByTestId ( 'named-form' ) ,
92
97
radio : getByTestId ( 'a-radio-1' ) ,
93
98
radio2 : getByTestId ( 'a-radio-2' ) ,
94
99
input : getByTestId ( 'a-input-1' ) ,
@@ -99,7 +104,6 @@ function setup() {
99
104
100
105
test ( 'getRoles returns expected roles for various dom nodes' , ( ) => {
101
106
const {
102
- section,
103
107
anchor,
104
108
h1,
105
109
h2,
@@ -120,17 +124,17 @@ test('getRoles returns expected roles for various dom nodes', () => {
120
124
td1,
121
125
td2,
122
126
td3,
123
- form,
124
127
radio,
125
128
radio2,
126
129
input,
127
130
input2,
128
131
textarea,
132
+ namedSection,
133
+ namedForm,
129
134
} = setup ( )
130
135
131
- expect ( getRoles ( section ) ) . toEqual ( {
136
+ expect ( getRoles ( namedSection ) ) . toEqual ( {
132
137
link : [ anchor ] ,
133
- region : [ section ] ,
134
138
heading : [ h1 , h2 , h3 ] ,
135
139
navigation : [ nav ] ,
136
140
radio : [ radio , radio2 ] ,
@@ -140,27 +144,28 @@ test('getRoles returns expected roles for various dom nodes', () => {
140
144
table : [ table ] ,
141
145
row : [ tr ] ,
142
146
cell : [ td1 , td2 , td3 ] ,
143
- form : [ form ] ,
144
147
textbox : [ input , input2 , textarea ] ,
145
148
rowgroup : [ tbody ] ,
146
149
command : [ menuItem , menuItem2 ] ,
147
150
menuitem : [ menuItem , menuItem2 ] ,
151
+ form : [ namedForm ] ,
152
+ region : [ namedSection ] ,
148
153
} )
149
154
} )
150
155
151
156
test ( 'logRoles calls console.log with output from prettyRoles' , ( ) => {
152
- const { section } = setup ( )
153
- logRoles ( section )
157
+ const { namedSection } = setup ( )
158
+ logRoles ( namedSection )
154
159
expect ( console . log ) . toHaveBeenCalledTimes ( 1 )
155
160
expect ( console . log . mock . calls [ 0 ] [ 0 ] ) . toMatchSnapshot ( )
156
161
} )
157
162
158
163
test ( 'getImplicitAriaRoles returns expected roles for various dom nodes' , ( ) => {
159
- const { section , h1, form , radio, input} = setup ( )
164
+ const { namedSection , h1, unnamedForm , radio, input} = setup ( )
160
165
161
- expect ( getImplicitAriaRoles ( section ) ) . toEqual ( [ 'region' ] )
166
+ expect ( getImplicitAriaRoles ( namedSection ) ) . toEqual ( [ 'region' ] )
162
167
expect ( getImplicitAriaRoles ( h1 ) ) . toEqual ( [ 'heading' ] )
163
- expect ( getImplicitAriaRoles ( form ) ) . toEqual ( [ 'form' ] )
168
+ expect ( getImplicitAriaRoles ( unnamedForm ) ) . toEqual ( [ ] )
164
169
expect ( getImplicitAriaRoles ( radio ) ) . toEqual ( [ 'radio' ] )
165
170
expect ( getImplicitAriaRoles ( input ) ) . toEqual ( [ 'textbox' ] )
166
171
} )
0 commit comments