@@ -26,12 +26,12 @@ const parserOptions = {
2626const ruleTester = new RuleTester ( ) ;
2727
2828const customMissingPropError = type => ( {
29- message : `${ type } elements must have an alt prop` ,
29+ message : `${ type } elements must have an alt prop. ` ,
3030 type : 'JSXOpeningElement'
3131} ) ;
3232
3333const 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. ` ,
3535 type : 'JSXOpeningElement'
3636} ) ;
3737
@@ -65,6 +65,10 @@ ruleTester.run('img-uses-alt', rule, {
6565 { code : '<img alt={foo.bar || ""} />' , parserOptions } ,
6666 { code : '<img alt={bar() || ""} />' , parserOptions } ,
6767 { 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 } ,
6872 { code : '<img alt=" " />' , parserOptions } , // For decorative images.
6973
7074 // CUSTOM ELEMENT TESTS FOR STRING OPTION
@@ -120,6 +124,9 @@ ruleTester.run('img-uses-alt', rule, {
120124 { code : '<img alt={undefined} />;' , errors : [ expectedAltValueError ] , parserOptions } ,
121125 { code : '<img alt={`${undefined}`} />;' , errors : [ expectedAltValueError ] , parserOptions } ,
122126 { 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 } ,
123130 { code : '<img src="xyz" />' , errors : [ expectedMissingPropError ] , parserOptions } ,
124131 { code : '<img {...this.props} />' , errors : [ expectedMissingPropError ] , parserOptions } ,
125132 { code : '<img alt={false || false} />' , errors : [ expectedAltValueError ] , parserOptions } ,
0 commit comments