source: frontend/node_modules/eslint-plugin-jsx-a11y/__tests__/src/rules/lang-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.0 KB
Line 
1/**
2 * @fileoverview Enforce lang attribute has a valid value.
3 * @author Ethan Cohen
4 */
5
6// -----------------------------------------------------------------------------
7// Requirements
8// -----------------------------------------------------------------------------
9
10import { RuleTester } from 'eslint';
11import parserOptionsMapper from '../../__util__/parserOptionsMapper';
12import parsers from '../../__util__/helpers/parsers';
13import rule from '../../../src/rules/lang';
14
15// -----------------------------------------------------------------------------
16// Tests
17// -----------------------------------------------------------------------------
18
19const ruleTester = new RuleTester();
20
21const expectedError = {
22 message: 'lang attribute must have a valid value.',
23 type: 'JSXAttribute',
24};
25
26const componentsSettings = {
27 'jsx-a11y': {
28 polymorphicPropName: 'as',
29 components: {
30 Foo: 'html',
31 },
32 },
33};
34
35ruleTester.run('lang', rule, {
36 valid: parsers.all([].concat(
37 { code: '<div />;' },
38 { code: '<div foo="bar" />;' },
39 { code: '<div lang="foo" />;' },
40 { code: '<html lang="en" />' },
41 { code: '<html lang="en-US" />' },
42 { code: '<html lang="zh-Hans" />' },
43 { code: '<html lang="zh-Hant-HK" />' },
44 { code: '<html lang="zh-yue-Hant" />' },
45 { code: '<html lang="ja-Latn" />' },
46 { code: '<html lang={foo} />' },
47 { code: '<HTML lang="foo" />' },
48 { code: '<Foo lang={undefined} />' },
49 { code: '<Foo lang="en" />', settings: componentsSettings },
50 { code: '<Box as="html" lang="en" />', settings: componentsSettings },
51 )).map(parserOptionsMapper),
52 invalid: parsers.all([].concat(
53 { code: '<html lang="foo" />', errors: [expectedError] },
54 { code: '<html lang="zz-LL" />', errors: [expectedError] },
55 { code: '<html lang={undefined} />', errors: [expectedError] },
56 { code: '<Foo lang={undefined} />', settings: componentsSettings, errors: [expectedError] },
57 { code: '<Box as="html" lang="foo" />', settings: componentsSettings, errors: [expectedError] },
58 )).map(parserOptionsMapper),
59});
Note: See TracBrowser for help on using the repository browser.