Skip to content

Commit

Permalink
[Tests] img-redundant-alt-test: add passing tests
Browse files Browse the repository at this point in the history
- Add test cases with optional chaining
- Add parserOptions prop to each test case to configure parser behaviour

Closes #794
  • Loading branch information
uncommon-type authored and ljharb committed Feb 18, 2022
1 parent f878d3b commit ea877c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 10 additions & 3 deletions __tests__/src/rules/img-redundant-alt-test.js
Expand Up @@ -8,6 +8,8 @@
// -----------------------------------------------------------------------------

import { RuleTester } from 'eslint';
import semver from 'semver';
import { version as eslintVersion } from 'eslint/package.json';
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
import rule from '../../../src/rules/img-redundant-alt';

Expand All @@ -28,7 +30,7 @@ const expectedError = {
};

ruleTester.run('img-redundant-alt', rule, {
valid: [
valid: [].concat(
{ code: '<img alt="foo" />;' },
{ code: '<img alt="picture of me taking a photo of an image" aria-hidden />' },
{ code: '<img aria-hidden alt="photo of image" />' },
Expand All @@ -52,11 +54,16 @@ ruleTester.run('img-redundant-alt', rule, {
{ code: '<img alt={function(e){}} />' },
{ code: '<img aria-hidden={false} alt="Doing cool things." />' },
{ code: '<UX.Layout>test</UX.Layout>' },
{ code: '<img alt={imageAlt} />' },
{ code: '<img alt />' },
{ code: '<img alt={imageAlt} />' },
{ code: '<img alt={imageAlt.name} />' },
semver.satisfies(eslintVersion, '>= 6') ? [
{ code: '<img alt={imageAlt?.name} />', parserOptions: { ecmaVersion: 2020 } },
{ code: '<img alt="Doing cool things" aria-hidden={foo?.bar}/>', parserOptions: { ecmaVersion: 2020 } },
] : [],
{ code: '<img alt="Photography" />;' },
{ code: '<img alt="ImageMagick" />;' },
].map(parserOptionsMapper),
).map(parserOptionsMapper),
invalid: [
{ code: '<img alt="Photo of friend." />;', errors: [expectedError] },
{ code: '<img alt="Picture of friend." />;', errors: [expectedError] },
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -73,7 +73,8 @@
"has": "^1.0.3",
"jsx-ast-utils": "^3.2.1",
"language-tags": "^1.0.5",
"minimatch": "^3.0.5"
"minimatch": "^3.0.5",
"semver": "^6.0.0"
},
"peerDependencies": {
"eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8"
Expand Down

0 comments on commit ea877c4

Please sign in to comment.