@@ -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' ,
@@ -83,6 +86,8 @@ ruleTester.run('alt-text', rule, {
83
86
{ code : '<img alt={error ? "not working": "working"} />' } ,
84
87
{ code : '<img alt={undefined ? "working": "not working"} />' } ,
85
88
{ code : '<img alt={plugin.name + " Logo"} />' } ,
89
+ { code : '<img aria-label="foo" />' } ,
90
+ { code : '<img aria-labelledby="id1" />' } ,
86
91
87
92
// DEFAULT <object> TESTS
88
93
{ code : '<object aria-label="foo" />' } ,
@@ -168,25 +173,41 @@ ruleTester.run('alt-text', rule, {
168
173
{ code : '<img alt role="presentation" />;' , errors : [ altValueError ( 'img' ) ] } ,
169
174
{ code : '<img role="presentation" />;' , errors : [ preferAltError ( ) ] } ,
170
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 ] } ,
171
180
172
181
// DEFAULT ELEMENT 'object' TESTS
173
182
{ code : '<object />' , errors : [ objectError ] } ,
174
183
{ code : '<object><div aria-hidden /></object>' , errors : [ objectError ] } ,
175
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 ] } ,
176
189
177
190
// DEFAULT ELEMENT 'area' TESTS
178
191
{ code : '<area />' , errors : [ areaError ] } ,
179
192
{ code : '<area alt />' , errors : [ areaError ] } ,
180
193
{ code : '<area alt={undefined} />' , errors : [ areaError ] } ,
181
194
{ code : '<area src="xyz" />' , errors : [ areaError ] } ,
182
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 ] } ,
183
200
184
201
// DEFAULT ELEMENT 'input type="image"' TESTS
185
202
{ code : '<input type="image" />' , errors : [ inputImageError ] } ,
186
203
{ code : '<input type="image" alt />' , errors : [ inputImageError ] } ,
187
204
{ code : '<input type="image" alt={undefined} />' , errors : [ inputImageError ] } ,
188
205
{ code : '<input type="image">Foo</input>' , errors : [ inputImageError ] } ,
189
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 ] } ,
190
211
191
212
// CUSTOM ELEMENT TESTS FOR ARRAY OPTION TESTS
192
213
{
0 commit comments