source: frontend/node_modules/eslint-plugin-jsx-a11y/__tests__/src/rules/aria-props-test.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 2 weeks ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/**
2 * @fileoverview Enforce all aria-* properties are valid.
3 * @author Ethan Cohen
4 */
5
6// -----------------------------------------------------------------------------
7// Requirements
8// -----------------------------------------------------------------------------
9
10import { aria } from 'aria-query';
11import { RuleTester } from 'eslint';
12import parserOptionsMapper from '../../__util__/parserOptionsMapper';
13import parsers from '../../__util__/helpers/parsers';
14import rule from '../../../src/rules/aria-props';
15import getSuggestion from '../../../src/util/getSuggestion';
16
17// -----------------------------------------------------------------------------
18// Tests
19// -----------------------------------------------------------------------------
20
21const ruleTester = new RuleTester();
22const ariaAttributes = aria.keys();
23
24const errorMessage = (name) => {
25 const suggestions = getSuggestion(name, ariaAttributes);
26 const message = `${name}: This attribute is an invalid ARIA attribute.`;
27
28 if (suggestions.length > 0) {
29 return {
30 type: 'JSXAttribute',
31 message: `${message} Did you mean to use ${suggestions}?`,
32 };
33 }
34
35 return {
36 type: 'JSXAttribute',
37 message,
38 };
39};
40
41// Create basic test cases using all valid role types.
42const basicValidityTests = ariaAttributes.map((prop) => ({
43 code: `<div ${prop.toLowerCase()}="foobar" />`,
44}));
45
46ruleTester.run('aria-props', rule, {
47 valid: parsers.all([].concat(
48 // Variables should pass, as we are only testing literals.
49 { code: '<div />' },
50 { code: '<div></div>' },
51 { code: '<div aria="wee"></div>' }, // Needs aria-*
52 { code: '<div abcARIAdef="true"></div>' },
53 { code: '<div fooaria-foobar="true"></div>' },
54 { code: '<div fooaria-hidden="true"></div>' },
55 { code: '<Bar baz />' },
56 { code: '<input type="text" aria-errormessage="foobar" />' },
57 )).concat(basicValidityTests).map(parserOptionsMapper),
58 invalid: parsers.all([].concat(
59 { code: '<div aria-="foobar" />', errors: [errorMessage('aria-')] },
60 {
61 code: '<div aria-labeledby="foobar" />',
62 errors: [errorMessage('aria-labeledby')],
63 },
64 {
65 code: '<div aria-skldjfaria-klajsd="foobar" />',
66 errors: [errorMessage('aria-skldjfaria-klajsd')],
67 },
68 )).map(parserOptionsMapper),
69});
Note: See TracBrowser for help on using the repository browser.