astro-ghostcms/.pnpm-store/v3/files/d8/3be6f0004a681f985e2947baab6...

45 lines
1.8 KiB
Plaintext
Raw Normal View History

2024-02-14 14:10:47 +00:00
/**
* @fileoverview Enforce `aria-hidden="true"` is not used on focusable elements.
* @author Kate Higa
*/
// -----------------------------------------------------------------------------
// Requirements
// -----------------------------------------------------------------------------
import { RuleTester } from 'eslint';
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
import parsers from '../../__util__/helpers/parsers';
import rule from '../../../src/rules/no-aria-hidden-on-focusable';
// -----------------------------------------------------------------------------
// Tests
// -----------------------------------------------------------------------------
const ruleTester = new RuleTester();
const expectedError = {
message: 'aria-hidden="true" must not be set on focusable elements.',
type: 'JSXOpeningElement',
};
ruleTester.run('no-aria-hidden-on-focusable', rule, {
valid: parsers.all([].concat(
{ code: '<div aria-hidden="true" />;' },
{ code: '<div onClick={() => void 0} aria-hidden="true" />;' },
{ code: '<img aria-hidden="true" />' },
{ code: '<a aria-hidden="false" href="#" />' },
{ code: '<button aria-hidden="true" tabIndex="-1" />' },
{ code: '<button />' },
{ code: '<a href="/" />' },
)).map(parserOptionsMapper),
invalid: parsers.all([].concat(
{ code: '<div aria-hidden="true" tabIndex="0" />;', errors: [expectedError] },
{ code: '<input aria-hidden="true" />;', errors: [expectedError] },
{ code: '<a href="/" aria-hidden="true" />', errors: [expectedError] },
{ code: '<button aria-hidden="true" />', errors: [expectedError] },
{ code: '<textarea aria-hidden="true" />', errors: [expectedError] },
{ code: '<p tabindex="0" aria-hidden="true">text</p>;', errors: [expectedError] },
)).map(parserOptionsMapper),
});