@@ -29,6 +29,9 @@ Use alt="" for presentational images.`,
29
29
type : 'JSXOpeningElement' ,
30
30
} ) ;
31
31
32
+ const ariaLabelValueError = 'The aria-label attribute must have a value. The alt attribute is preferred over aria-label for images.' ;
33
+ const ariaLabelledbyValueError = 'The aria-labelledby attribute must have a value. The alt attribute is preferred over aria-labelledby for images.' ;
34
+
32
35
const preferAltError = ( ) => ( {
33
36
message : 'Prefer alt="" over a presentational role. First rule of aria is to not use aria if it can be achieved via native HTML.' ,
34
37
type : 'JSXOpeningElement' ,
@@ -170,25 +173,41 @@ ruleTester.run('alt-text', rule, {
170
173
{ code : '<img alt role="presentation" />;' , errors : [ altValueError ( 'img' ) ] } ,
171
174
{ code : '<img role="presentation" />;' , errors : [ preferAltError ( ) ] } ,
172
175
{ code : '<img role="none" />;' , errors : [ preferAltError ( ) ] } ,
176
+ { code : '<img aria-label={undefined} />' , errors : [ ariaLabelValueError ] } ,
177
+ { code : '<img aria-labelledby={undefined} />' , errors : [ ariaLabelledbyValueError ] } ,
178
+ { code : '<img aria-label="" />' , errors : [ ariaLabelValueError ] } ,
179
+ { code : '<img aria-labelledby="" />' , errors : [ ariaLabelledbyValueError ] } ,
173
180
174
181
// DEFAULT ELEMENT 'object' TESTS
175
182
{ code : '<object />' , errors : [ objectError ] } ,
176
183
{ code : '<object><div aria-hidden /></object>' , errors : [ objectError ] } ,
177
184
{ code : '<object title={undefined} />' , errors : [ objectError ] } ,
185
+ { code : '<object aria-label="" />' , errors : [ objectError ] } ,
186
+ { code : '<object aria-labelledby="" />' , errors : [ objectError ] } ,
187
+ { code : '<object aria-label={undefined} />' , errors : [ objectError ] } ,
188
+ { code : '<object aria-labelledby={undefined} />' , errors : [ objectError ] } ,
178
189
179
190
// DEFAULT ELEMENT 'area' TESTS
180
191
{ code : '<area />' , errors : [ areaError ] } ,
181
192
{ code : '<area alt />' , errors : [ areaError ] } ,
182
193
{ code : '<area alt={undefined} />' , errors : [ areaError ] } ,
183
194
{ code : '<area src="xyz" />' , errors : [ areaError ] } ,
184
195
{ code : '<area {...this.props} />' , errors : [ areaError ] } ,
196
+ { code : '<area aria-label="" />' , errors : [ areaError ] } ,
197
+ { code : '<area aria-label={undefined} />' , errors : [ areaError ] } ,
198
+ { code : '<area aria-labelledby="" />' , errors : [ areaError ] } ,
199
+ { code : '<area aria-labelledby={undefined} />' , errors : [ areaError ] } ,
185
200
186
201
// DEFAULT ELEMENT 'input type="image"' TESTS
187
202
{ code : '<input type="image" />' , errors : [ inputImageError ] } ,
188
203
{ code : '<input type="image" alt />' , errors : [ inputImageError ] } ,
189
204
{ code : '<input type="image" alt={undefined} />' , errors : [ inputImageError ] } ,
190
205
{ code : '<input type="image">Foo</input>' , errors : [ inputImageError ] } ,
191
206
{ code : '<input type="image" {...this.props} />' , errors : [ inputImageError ] } ,
207
+ { code : '<input type="image" aria-label="" />' , errors : [ inputImageError ] } ,
208
+ { code : '<input type="image" aria-label={undefined} />' , errors : [ inputImageError ] } ,
209
+ { code : '<input type="image" aria-labelledby="" />' , errors : [ inputImageError ] } ,
210
+ { code : '<input type="image" aria-labelledby={undefined} />' , errors : [ inputImageError ] } ,
192
211
193
212
// CUSTOM ELEMENT TESTS FOR ARRAY OPTION TESTS
194
213
{
0 commit comments