Permalink
Cannot retrieve contributors at this time
94 lines (88 sloc)
2.64 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/node_modules/eslint-plugin-jsx-a11y/__tests__/src/rules/aria-activedescendant-has-tabindex-test.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @fileoverview Enforce elements with aria-activedescendant are tabbable. | |
* @author Jesse Beach <@jessebeach> | |
*/ | |
// ----------------------------------------------------------------------------- | |
// Requirements | |
// ----------------------------------------------------------------------------- | |
import { RuleTester } from 'eslint'; | |
import parserOptionsMapper from '../../__util__/parserOptionsMapper'; | |
import rule from '../../../src/rules/aria-activedescendant-has-tabindex'; | |
// ----------------------------------------------------------------------------- | |
// Tests | |
// ----------------------------------------------------------------------------- | |
const ruleTester = new RuleTester(); | |
const expectedError = { | |
message: 'An element that manages focus with `aria-activedescendant` must have a tabindex', | |
type: 'JSXOpeningElement', | |
}; | |
ruleTester.run('aria-activedescendant-has-tabindex', rule, { | |
valid: [ | |
{ | |
code: '<CustomComponent />;', | |
}, | |
{ | |
code: '<CustomComponent aria-activedescendant={someID} />;', | |
}, | |
{ | |
code: '<CustomComponent aria-activedescendant={someID} tabIndex={0} />;', | |
}, | |
{ | |
code: '<CustomComponent aria-activedescendant={someID} tabIndex={-1} />;', | |
}, | |
{ | |
code: '<CustomComponent aria-activedescendant={someID} tabIndex={0} />;', | |
settings: { 'jsx-a11y': { components: { CustomComponent: 'div' } } }, | |
}, | |
{ | |
code: '<div />;', | |
}, | |
{ | |
code: '<input />;', | |
}, | |
{ | |
code: '<div tabIndex={0} />;', | |
}, | |
{ | |
code: '<div aria-activedescendant={someID} tabIndex={0} />;', | |
}, | |
{ | |
code: '<div aria-activedescendant={someID} tabIndex="0" />;', | |
}, | |
{ | |
code: '<div aria-activedescendant={someID} tabIndex={1} />;', | |
}, | |
{ | |
code: '<input aria-activedescendant={someID} />;', | |
}, | |
{ | |
code: '<input aria-activedescendant={someID} tabIndex={1} />;', | |
}, | |
{ | |
code: '<input aria-activedescendant={someID} tabIndex={0} />;', | |
}, | |
{ | |
code: '<input aria-activedescendant={someID} tabIndex={-1} />;', | |
}, | |
{ | |
code: '<div aria-activedescendant={someID} tabIndex={-1} />;', | |
}, | |
{ | |
code: '<div aria-activedescendant={someID} tabIndex="-1" />;', | |
}, | |
{ | |
code: '<input aria-activedescendant={someID} tabIndex={-1} />;', | |
}, | |
].map(parserOptionsMapper), | |
invalid: [ | |
{ | |
code: '<div aria-activedescendant={someID} />;', | |
errors: [expectedError], | |
}, | |
{ | |
code: '<CustomComponent aria-activedescendant={someID} />;', | |
errors: [expectedError], | |
settings: { 'jsx-a11y': { components: { CustomComponent: 'div' } } }, | |
}, | |
].map(parserOptionsMapper), | |
}); |