@@ -26,12 +26,12 @@ const parserOptions = {
26
26
const ruleTester = new RuleTester ( ) ;
27
27
28
28
const customMissingPropError = type => ( {
29
- message : `${ type } elements must have an alt prop` ,
29
+ message : `${ type } elements must have an alt prop. ` ,
30
30
type : 'JSXOpeningElement'
31
31
} ) ;
32
32
33
33
const customAltValueError = type => ( {
34
- message : `${ type } alt prop must have a value` ,
34
+ message : `${ type } alt prop must have a value. You can set alt="" if role="presentation" is applied. ` ,
35
35
type : 'JSXOpeningElement'
36
36
} ) ;
37
37
@@ -65,6 +65,10 @@ ruleTester.run('img-uses-alt', rule, {
65
65
{ code : '<img alt={foo.bar || ""} />' , parserOptions } ,
66
66
{ code : '<img alt={bar() || ""} />' , parserOptions } ,
67
67
{ code : '<img alt={foo.bar() || ""} />' , parserOptions } ,
68
+ { code : '<img alt="" role="presentation" />' , parserOptions } , // Allow alt to be undefined if role="presentation"
69
+ { code : '<img alt="" role={`presentation`} />' , parserOptions } ,
70
+ { code : '<img alt="" role={"presentation"} />' , parserOptions } ,
71
+ { code : '<img alt="this is lit..." role="presentation" />' , parserOptions } ,
68
72
{ code : '<img alt=" " />' , parserOptions } , // For decorative images.
69
73
70
74
// CUSTOM ELEMENT TESTS FOR STRING OPTION
@@ -120,6 +124,9 @@ ruleTester.run('img-uses-alt', rule, {
120
124
{ code : '<img alt={undefined} />;' , errors : [ expectedAltValueError ] , parserOptions } ,
121
125
{ code : '<img alt={`${undefined}`} />;' , errors : [ expectedAltValueError ] , parserOptions } ,
122
126
{ code : '<img alt="" />;' , errors : [ expectedAltValueError ] , parserOptions } ,
127
+ { code : '<img role="presentation" />;' , errors : [ expectedMissingPropError ] , parserOptions } ,
128
+ { code : '<img alt={undefined} role="presentation" />;' , errors : [ expectedAltValueError ] , parserOptions } ,
129
+ { code : '<img alt role="presentation" />;' , errors : [ expectedAltValueError ] , parserOptions } ,
123
130
{ code : '<img src="xyz" />' , errors : [ expectedMissingPropError ] , parserOptions } ,
124
131
{ code : '<img {...this.props} />' , errors : [ expectedMissingPropError ] , parserOptions } ,
125
132
{ code : '<img alt={false || false} />' , errors : [ expectedAltValueError ] , parserOptions } ,
0 commit comments