|
| 1 | +/** |
| 2 | + * @fileoverview Enforce `aria-hidden="true"` is not used on focusable elements. |
| 3 | + * @author Kate Higa |
| 4 | +*/ |
| 5 | + |
| 6 | +// ----------------------------------------------------------------------------- |
| 7 | +// Requirements |
| 8 | +// ----------------------------------------------------------------------------- |
| 9 | + |
| 10 | +import { RuleTester } from 'eslint'; |
| 11 | +import parserOptionsMapper from '../../__util__/parserOptionsMapper'; |
| 12 | +import rule from '../../../src/rules/no-aria-hidden-on-focusable'; |
| 13 | +// ----------------------------------------------------------------------------- |
| 14 | +// Tests |
| 15 | +// ----------------------------------------------------------------------------- |
| 16 | + |
| 17 | +const ruleTester = new RuleTester(); |
| 18 | + |
| 19 | +const expectedError = { |
| 20 | + message: 'aria-hidden="true" must not be set on focusable elements.', |
| 21 | + type: 'JSXOpeningElement', |
| 22 | +}; |
| 23 | + |
| 24 | +ruleTester.run('no-aria-hidden-on-focusable', rule, { |
| 25 | + valid: [ |
| 26 | + { code: '<div aria-hidden="true" />;' }, |
| 27 | + { code: '<div onClick={() => void 0} aria-hidden="true" />;' }, |
| 28 | + { code: '<img aria-hidden="true" />' }, |
| 29 | + { code: '<a aria-hidden="false" href="#" />' }, |
| 30 | + { code: '<button aria-hidden="true" tabIndex="-1" />' }, |
| 31 | + { code: '<button />' }, |
| 32 | + { code: '<a href="/" />' }, |
| 33 | + ].map(parserOptionsMapper), |
| 34 | + invalid: [ |
| 35 | + { code: '<div aria-hidden="true" tabIndex="0" />;', errors: [expectedError] }, |
| 36 | + { code: '<input aria-hidden="true" />;', errors: [expectedError] }, |
| 37 | + { code: '<a href="/" aria-hidden="true" />', errors: [expectedError] }, |
| 38 | + { code: '<button aria-hidden="true" />', errors: [expectedError] }, |
| 39 | + { code: '<textarea aria-hidden="true" />', errors: [expectedError] }, |
| 40 | + { code: '<p tabindex="0" aria-hidden="true">text</p>;', errors: [expectedError] }, |
| 41 | + ].map(parserOptionsMapper), |
| 42 | +}); |
0 commit comments