@@ -26,6 +26,11 @@ const expectedError = {
26
26
type : 'JSXOpeningElement' ,
27
27
} ;
28
28
29
+ const expectedErrorNoLabel = {
30
+ message : 'A form label must have accessible text.' ,
31
+ type : 'JSXOpeningElement' ,
32
+ } ;
33
+
29
34
const componentsSettings = {
30
35
'jsx-a11y' : {
31
36
components : {
@@ -132,12 +137,12 @@ const nestingInvalid = [
132
137
] ;
133
138
134
139
const neverValid = [
135
- { code : '<label htmlFor="js_id" />' , errors : [ expectedError ] } ,
136
- { code : '<label htmlFor="js_id"><input /></label>' , errors : [ expectedError ] } ,
137
- { code : '<label htmlFor="js_id"><textarea /></label>' , errors : [ expectedError ] } ,
138
- { code : '<label></label>' , errors : [ expectedError ] } ,
140
+ { code : '<label htmlFor="js_id" />' , errors : [ expectedErrorNoLabel ] } ,
141
+ { code : '<label htmlFor="js_id"><input /></label>' , errors : [ expectedErrorNoLabel ] } ,
142
+ { code : '<label htmlFor="js_id"><textarea /></label>' , errors : [ expectedErrorNoLabel ] } ,
143
+ { code : '<label></label>' , errors : [ expectedErrorNoLabel ] } ,
139
144
{ code : '<label>A label</label>' , errors : [ expectedError ] } ,
140
- { code : '<div><label /><input /></div>' , errors : [ expectedError ] } ,
145
+ { code : '<div><label /><input /></div>' , errors : [ expectedErrorNoLabel ] } ,
141
146
{ code : '<div><label>A label</label><input /></div>' , errors : [ expectedError ] } ,
142
147
// Custom label component.
143
148
{ code : '<CustomLabel aria-label="A label" />' , options : [ { labelComponents : [ 'CustomLabel' ] } ] , errors : [ expectedError ] } ,
@@ -146,11 +151,11 @@ const neverValid = [
146
151
// Custom label attributes.
147
152
{ code : '<label label="A label" />' , options : [ { labelAttributes : [ 'label' ] } ] , errors : [ expectedError ] } ,
148
153
// Custom controlComponents.
149
- { code : '<label><span><CustomInput /></span></label>' , options : [ { controlComponents : [ 'CustomInput' ] } ] , errors : [ expectedError ] } ,
150
- { code : '<CustomLabel><span><CustomInput /></span></CustomLabel>' , options : [ { controlComponents : [ 'CustomInput' ] , labelComponents : [ 'CustomLabel' ] } ] , errors : [ expectedError ] } ,
151
- { code : '<CustomLabel><span><CustomInput /></span></CustomLabel>' , options : [ { controlComponents : [ 'CustomInput' ] , labelComponents : [ 'CustomLabel' ] , labelAttributes : [ 'label' ] } ] , errors : [ expectedError ] } ,
152
- { code : '<label><span><CustomInput /></span></label>' , settings : componentsSettings , errors : [ expectedError ] } ,
153
- { code : '<CustomLabel><span><CustomInput /></span></CustomLabel>' , settings : componentsSettings , errors : [ expectedError ] } ,
154
+ { code : '<label><span><CustomInput /></span></label>' , options : [ { controlComponents : [ 'CustomInput' ] } ] , errors : [ expectedErrorNoLabel ] } ,
155
+ { code : '<CustomLabel><span><CustomInput /></span></CustomLabel>' , options : [ { controlComponents : [ 'CustomInput' ] , labelComponents : [ 'CustomLabel' ] } ] , errors : [ expectedErrorNoLabel ] } ,
156
+ { code : '<CustomLabel><span><CustomInput /></span></CustomLabel>' , options : [ { controlComponents : [ 'CustomInput' ] , labelComponents : [ 'CustomLabel' ] , labelAttributes : [ 'label' ] } ] , errors : [ expectedErrorNoLabel ] } ,
157
+ { code : '<label><span><CustomInput /></span></label>' , settings : componentsSettings , errors : [ expectedErrorNoLabel ] } ,
158
+ { code : '<CustomLabel><span><CustomInput /></span></CustomLabel>' , settings : componentsSettings , errors : [ expectedErrorNoLabel ] } ,
154
159
] ;
155
160
// htmlFor valid
156
161
ruleTester . run ( ruleName , rule , {
0 commit comments