no-access-key-test.js
1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* eslint-env jest */
/**
* @fileoverview Enforce no accesskey attribute on element.
* @author Ethan Cohen
*/
// -----------------------------------------------------------------------------
// Requirements
// -----------------------------------------------------------------------------
import { RuleTester } from 'eslint';
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
import rule from '../../../src/rules/no-access-key';
// -----------------------------------------------------------------------------
// Tests
// -----------------------------------------------------------------------------
const ruleTester = new RuleTester();
const expectedError = {
message: 'No access key attribute allowed. Inconsistencies between keyboard shortcuts and keyboard comments used by screenreader and keyboard only users create a11y complications.',
type: 'JSXOpeningElement',
};
ruleTester.run('no-access-key', rule, {
valid: [
{ code: '<div />;' },
{ code: '<div {...props} />' },
{ code: '<div accessKey={undefined} />' },
].map(parserOptionsMapper),
invalid: [
{ code: '<div accesskey="h" />', errors: [expectedError] },
{ code: '<div accessKey="h" />', errors: [expectedError] },
{ code: '<div accessKey="h" {...props} />', errors: [expectedError] },
{ code: '<div acCesSKeY="y" />', errors: [expectedError] },
{ code: '<div accessKey={"y"} />', errors: [expectedError] },
{ code: '<div accessKey={`${y}`} />', errors: [expectedError] },
{
code: '<div accessKey={`${undefined}y${undefined}`} />',
errors: [expectedError],
},
{ code: '<div accessKey={`This is ${bad}`} />', errors: [expectedError] },
{ code: '<div accessKey={accessKey} />', errors: [expectedError] },
{ code: '<div accessKey={`${undefined}`} />', errors: [expectedError] },
{ code: '<div accessKey={`${undefined}${undefined}`} />', errors: [expectedError] },
].map(parserOptionsMapper),
});