|
| 1 | +/** |
| 2 | + * @fileoverview Enforce table element has child of caption with value. |
| 3 | + * @author Ethan Cohen |
| 4 | + */ |
| 5 | + |
| 6 | +'use strict'; |
| 7 | + |
| 8 | +// ----------------------------------------------------------------------------- |
| 9 | +// Requirements |
| 10 | +// ----------------------------------------------------------------------------- |
| 11 | + |
| 12 | +import rule from '../../../src/rules/table-uses-caption'; |
| 13 | +import { RuleTester } from 'eslint'; |
| 14 | + |
| 15 | +const parserOptions = { |
| 16 | + ecmaVersion: 6, |
| 17 | + ecmaFeatures: { |
| 18 | + jsx: true |
| 19 | + } |
| 20 | +}; |
| 21 | + |
| 22 | +// ----------------------------------------------------------------------------- |
| 23 | +// Tests |
| 24 | +// ----------------------------------------------------------------------------- |
| 25 | + |
| 26 | +const ruleTester = new RuleTester(); |
| 27 | + |
| 28 | +const expectedError = { |
| 29 | + message: `table elements must have a caption element as child to ` + |
| 30 | + `programatically associate captions for data tables.`, |
| 31 | + type: 'JSXOpeningElement' |
| 32 | +}; |
| 33 | + |
| 34 | +// const string = [ 'Avatar' ]; |
| 35 | +// const array = [ [ 'Thumbnail', 'Image' ] ]; |
| 36 | + |
| 37 | +// const customError = type => ({ |
| 38 | +// message: `${type} elements must have an alt tag.`, |
| 39 | +// type: 'JSXOpeningElement' |
| 40 | +// }); |
| 41 | + |
| 42 | +ruleTester.run('table-uses-caption', rule, { |
| 43 | + valid: [ |
| 44 | + // DEFAULT ELEMENT 'table' TESTS |
| 45 | + { code: '<table><caption>Cool data</caption></table>;', parserOptions }, |
| 46 | + { code: '<table><caption>`data of ${type}`</caption></table>;', parserOptions }, |
| 47 | + { code: '<table><caption><span>FOO</span></caption></table>;', parserOptions }, |
| 48 | + { code: '<table><th></th><tbody></tbody><caption><span>FOO</span></caption></table>;', parserOptions } |
| 49 | + ], |
| 50 | + invalid: [ |
| 51 | + { code: '<table><caption></caption></table>;', errors: [ expectedError ], parserOptions }, |
| 52 | + { code: '<table></table>;', errors: [ expectedError ], parserOptions }, |
| 53 | + { code: '<table><Caption>abc</Caption></table>;', errors: [ expectedError ], parserOptions }, |
| 54 | + { code: '<table><th>1</th><tbody></tbody></table>;', errors: [ expectedError ], parserOptions } |
| 55 | + ] |
| 56 | +}); |
0 commit comments