/** * @fileoverview Enforce ARIA state and property values are valid. * @author Ethan Cohen */ // ----------------------------------------------------------------------------- // Requirements // ----------------------------------------------------------------------------- import { aria } from 'aria-query'; import { RuleTester } from 'eslint'; import expect from 'expect'; import parserOptionsMapper from '../../__util__/parserOptionsMapper'; import parsers from '../../__util__/helpers/parsers'; import rule from '../../../src/rules/aria-proptypes'; const { validityCheck } = rule; // ----------------------------------------------------------------------------- // Tests // ----------------------------------------------------------------------------- const ruleTester = new RuleTester(); const errorMessage = (name) => { const { type, values: permittedValues, } = aria.get(name.toLowerCase()); switch (type) { case 'tristate': return { message: `The value for ${name} must be a boolean or the string "mixed".` }; case 'token': return { message: `The value for ${name} must be a single token from the following: ${permittedValues}.` }; case 'tokenlist': return { message: `The value for ${name} must be a list of one or more \ tokens from the following: ${permittedValues}.`, }; case 'idlist': return { message: `The value for ${name} must be a list of strings that represent DOM element IDs (idlist)` }; case 'id': return { message: `The value for ${name} must be a string that represents a DOM element ID` }; case 'boolean': case 'string': case 'integer': case 'number': default: return { message: `The value for ${name} must be a ${type}.` }; } }; describe('validityCheck', () => { it('should false for an unknown expected type', () => { expect(validityCheck( null, null, )).toBe(false); }); }); ruleTester.run('aria-proptypes', rule, { valid: parsers.all([].concat( // DON'T TEST INVALID ARIA-* PROPS { code: '
' }, { code: '
' }, // BOOLEAN { code: '
' }, { code: '