/** * @fileoverview Enforce heading (h1, h2, etc) elements contain accessible content. * @author Ethan Cohen */ // ----------------------------------------------------------------------------- // Requirements // ----------------------------------------------------------------------------- import { RuleTester } from 'eslint'; import parserOptionsMapper from '../../__util__/parserOptionsMapper'; import parsers from '../../__util__/helpers/parsers'; import rule from '../../../src/rules/heading-has-content'; // ----------------------------------------------------------------------------- // Tests // ----------------------------------------------------------------------------- const ruleTester = new RuleTester(); const expectedError = { message: 'Headings must have content and the content must be accessible by a screen reader.', type: 'JSXOpeningElement', }; const components = [{ components: ['Heading', 'Title'], }]; const componentsSettings = { 'jsx-a11y': { components: { CustomInput: 'input', Title: 'h1', Heading: 'h2', }, }, }; ruleTester.run('heading-has-content', rule, { valid: parsers.all([].concat( // DEFAULT ELEMENT TESTS { code: '
;' }, { code: '

Foo

' }, { code: '

Foo

' }, { code: '

Foo

' }, { code: '

Foo

' }, { code: '
Foo
' }, { code: '
Foo
' }, { code: '
123
' }, { code: '

' }, { code: '

{foo}

' }, { code: '

{foo.bar}

' }, { code: '

' }, { code: '

' }, // CUSTOM ELEMENT TESTS FOR COMPONENTS OPTION { code: 'Foo', options: components }, { code: 'Foo', options: components }, { code: '', options: components }, { code: '{foo}', options: components }, { code: '{foo.bar}', options: components }, { code: '', options: components }, { code: '', options: components }, { code: '

' }, // CUSTOM ELEMENT TESTS FOR COMPONENTS SETTINGS { code: 'Foo', settings: componentsSettings }, { code: '

' }, )).map(parserOptionsMapper), invalid: parsers.all([].concat( // DEFAULT ELEMENT TESTS { code: '

', errors: [expectedError] }, { code: '

', errors: [expectedError] }, { code: '

{undefined}

', errors: [expectedError] }, { code: '

', errors: [expectedError] }, // CUSTOM ELEMENT TESTS FOR COMPONENTS OPTION { code: '', errors: [expectedError], options: components }, { code: '', errors: [expectedError], options: components }, { code: '{undefined}', errors: [expectedError], options: components }, // CUSTOM ELEMENT TESTS FOR COMPONENTS SETTINGS { code: '', errors: [expectedError], settings: componentsSettings }, { code: '

', errors: [expectedError], settings: componentsSettings }, )).map(parserOptionsMapper), });