| 1 | /**
|
|---|
| 2 | * @fileoverview Enforce scope prop is only used on <th> elements.
|
|---|
| 3 | * @author Ethan Cohen
|
|---|
| 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/scope';
|
|---|
| 14 |
|
|---|
| 15 | // -----------------------------------------------------------------------------
|
|---|
| 16 | // Tests
|
|---|
| 17 | // -----------------------------------------------------------------------------
|
|---|
| 18 |
|
|---|
| 19 | const ruleTester = new RuleTester();
|
|---|
| 20 |
|
|---|
| 21 | const expectedError = {
|
|---|
| 22 | message: 'The scope prop can only be used on <th> elements.',
|
|---|
| 23 | type: 'JSXAttribute',
|
|---|
| 24 | };
|
|---|
| 25 |
|
|---|
| 26 | const componentsSettings = {
|
|---|
| 27 | 'jsx-a11y': {
|
|---|
| 28 | components: {
|
|---|
| 29 | Foo: 'div',
|
|---|
| 30 | TableHeader: 'th',
|
|---|
| 31 | },
|
|---|
| 32 | },
|
|---|
| 33 | };
|
|---|
| 34 |
|
|---|
| 35 | ruleTester.run('scope', rule, {
|
|---|
| 36 | valid: parsers.all([].concat(
|
|---|
| 37 | { code: '<div />;' },
|
|---|
| 38 | { code: '<div foo />;' },
|
|---|
| 39 | { code: '<th scope />' },
|
|---|
| 40 | { code: '<th scope="row" />' },
|
|---|
| 41 | { code: '<th scope={foo} />' },
|
|---|
| 42 | { code: '<th scope={"col"} {...props} />' },
|
|---|
| 43 | { code: '<Foo scope="bar" {...props} />' },
|
|---|
| 44 | { code: '<TableHeader scope="row" />', settings: componentsSettings },
|
|---|
| 45 | )).map(parserOptionsMapper),
|
|---|
| 46 | invalid: parsers.all([].concat(
|
|---|
| 47 | { code: '<div scope />', errors: [expectedError] },
|
|---|
| 48 | { code: '<Foo scope="bar" />', settings: componentsSettings, errors: [expectedError] },
|
|---|
| 49 | )).map(parserOptionsMapper),
|
|---|
| 50 | });
|
|---|