Permalink
Cannot retrieve contributors at this time
67 lines (59 sloc)
2.24 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/no-autofocus-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 autoFocus prop is not used. | |
* @author Ethan Cohen <@evcohen> | |
*/ | |
// ----------------------------------------------------------------------------- | |
// Requirements | |
// ----------------------------------------------------------------------------- | |
import { RuleTester } from 'eslint'; | |
import parserOptionsMapper from '../../__util__/parserOptionsMapper'; | |
import rule from '../../../src/rules/no-autofocus'; | |
// ----------------------------------------------------------------------------- | |
// Tests | |
// ----------------------------------------------------------------------------- | |
const ruleTester = new RuleTester(); | |
const expectedError = { | |
message: 'The autoFocus prop should not be used, as it can reduce usability and accessibility for users.', | |
type: 'JSXAttribute', | |
}; | |
const ignoreNonDOMSchema = [ | |
{ | |
ignoreNonDOM: true, | |
}, | |
]; | |
const componentsSettings = { | |
'jsx-a11y': { | |
components: { | |
Button: 'button', | |
}, | |
}, | |
}; | |
ruleTester.run('no-autofocus', rule, { | |
valid: [ | |
{ code: '<div />;' }, | |
{ code: '<div autofocus />;' }, | |
{ code: '<input autofocus="true" />;' }, | |
{ code: '<Foo bar />' }, | |
{ code: '<Foo autoFocus />', options: ignoreNonDOMSchema }, | |
{ code: '<div><div autofocus /></div>', options: ignoreNonDOMSchema }, | |
{ code: '<Button />', settings: componentsSettings }, | |
{ code: '<Button />', options: ignoreNonDOMSchema, settings: componentsSettings }, | |
].map(parserOptionsMapper), | |
invalid: [ | |
{ code: '<div autoFocus />', errors: [expectedError] }, | |
{ code: '<div autoFocus={true} />', errors: [expectedError] }, | |
{ code: '<div autoFocus={false} />', errors: [expectedError] }, | |
{ code: '<div autoFocus={undefined} />', errors: [expectedError] }, | |
{ code: '<div autoFocus="true" />', errors: [expectedError] }, | |
{ code: '<div autoFocus="false" />', errors: [expectedError] }, | |
{ code: '<input autoFocus />', errors: [expectedError] }, | |
{ code: '<Foo autoFocus />', errors: [expectedError] }, | |
{ code: '<Button autoFocus />', errors: [expectedError], settings: componentsSettings }, | |
{ | |
code: '<Button autoFocus />', | |
errors: [expectedError], | |
options: ignoreNonDOMSchema, | |
settings: componentsSettings, | |
}, | |
].map(parserOptionsMapper), | |
}); |