@@ -26,6 +26,11 @@ const expectedError = {
2626 type : 'JSXOpeningElement' ,
2727} ;
2828
29+ const expectedErrorNoLabel = {
30+ message : 'A form label must have accessible text.' ,
31+ type : 'JSXOpeningElement' ,
32+ } ;
33+
2934const componentsSettings = {
3035 'jsx-a11y' : {
3136 components : {
@@ -132,12 +137,12 @@ const nestingInvalid = [
132137] ;
133138
134139const 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 ] } ,
139144 { code : '<label>A label</label>' , errors : [ expectedError ] } ,
140- { code : '<div><label /><input /></div>' , errors : [ expectedError ] } ,
145+ { code : '<div><label /><input /></div>' , errors : [ expectedErrorNoLabel ] } ,
141146 { code : '<div><label>A label</label><input /></div>' , errors : [ expectedError ] } ,
142147 // Custom label component.
143148 { code : '<CustomLabel aria-label="A label" />' , options : [ { labelComponents : [ 'CustomLabel' ] } ] , errors : [ expectedError ] } ,
@@ -146,11 +151,11 @@ const neverValid = [
146151 // Custom label attributes.
147152 { code : '<label label="A label" />' , options : [ { labelAttributes : [ 'label' ] } ] , errors : [ expectedError ] } ,
148153 // 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 ] } ,
154159] ;
155160// htmlFor valid
156161ruleTester . run ( ruleName , rule , {
0 commit comments