| 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 parsers from '../../__util__/helpers/parsers';
|
|---|
| 13 | import rule from '../../../src/rules/no-aria-hidden-on-focusable';
|
|---|
| 14 |
|
|---|
| 15 | // -----------------------------------------------------------------------------
|
|---|
| 16 | // Tests
|
|---|
| 17 | // -----------------------------------------------------------------------------
|
|---|
| 18 |
|
|---|
| 19 | const ruleTester = new RuleTester();
|
|---|
| 20 |
|
|---|
| 21 | const expectedError = {
|
|---|
| 22 | message: 'aria-hidden="true" must not be set on focusable elements.',
|
|---|
| 23 | type: 'JSXOpeningElement',
|
|---|
| 24 | };
|
|---|
| 25 |
|
|---|
| 26 | ruleTester.run('no-aria-hidden-on-focusable', rule, {
|
|---|
| 27 | valid: parsers.all([].concat(
|
|---|
| 28 | { code: '<div aria-hidden="true" />;' },
|
|---|
| 29 | { code: '<div onClick={() => void 0} aria-hidden="true" />;' },
|
|---|
| 30 | { code: '<img aria-hidden="true" />' },
|
|---|
| 31 | { code: '<a aria-hidden="false" href="#" />' },
|
|---|
| 32 | { code: '<button aria-hidden="true" tabIndex="-1" />' },
|
|---|
| 33 | { code: '<button />' },
|
|---|
| 34 | { code: '<a href="/" />' },
|
|---|
| 35 | )).map(parserOptionsMapper),
|
|---|
| 36 | invalid: parsers.all([].concat(
|
|---|
| 37 | { code: '<div aria-hidden="true" tabIndex="0" />;', errors: [expectedError] },
|
|---|
| 38 | { code: '<input aria-hidden="true" />;', errors: [expectedError] },
|
|---|
| 39 | { code: '<a href="/" aria-hidden="true" />', errors: [expectedError] },
|
|---|
| 40 | { code: '<button aria-hidden="true" />', errors: [expectedError] },
|
|---|
| 41 | { code: '<textarea aria-hidden="true" />', errors: [expectedError] },
|
|---|
| 42 | { code: '<p tabindex="0" aria-hidden="true">text</p>;', errors: [expectedError] },
|
|---|
| 43 | )).map(parserOptionsMapper),
|
|---|
| 44 | });
|
|---|