Permalink
Cannot retrieve contributors at this time
56 lines (49 sloc)
2.12 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-onchange-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 usage of onBlur over onChange on select menus for accessibility. | |
* @author Ethan Cohen | |
*/ | |
// ----------------------------------------------------------------------------- | |
// Requirements | |
// ----------------------------------------------------------------------------- | |
import { RuleTester } from 'eslint'; | |
import parserOptionsMapper from '../../__util__/parserOptionsMapper'; | |
import rule from '../../../src/rules/no-onchange'; | |
// ----------------------------------------------------------------------------- | |
// Tests | |
// ----------------------------------------------------------------------------- | |
const ruleTester = new RuleTester(); | |
const expectedError = { | |
message: 'onBlur must be used instead of onchange, unless absolutely necessary and it causes no negative consequences for keyboard only or screen reader users.', | |
type: 'JSXOpeningElement', | |
}; | |
const componentsSettings = { | |
'jsx-a11y': { | |
components: { | |
CustomOption: 'option', | |
Input: 'input', | |
}, | |
}, | |
}; | |
ruleTester.run('no-onchange', rule, { | |
valid: [ | |
{ code: '<select onBlur={() => {}} />;' }, | |
{ code: '<select onBlur={handleOnBlur} />;' }, | |
{ code: '<option />;' }, | |
{ code: '<option onBlur={() => {}} onChange={() => {}} />;' }, | |
{ code: '<option {...props} />' }, | |
{ code: '<input onChange={() => {}} />;' }, | |
{ code: '<input onChange={handleOnChange} />;' }, | |
{ code: '<input />;' }, | |
{ code: '<input onChange={() => {}} onChange={() => {}} />;' }, | |
{ code: '<input {...props} />' }, | |
{ code: '<Input onChange={() => {}} />;', settings: componentsSettings }, | |
{ code: '<CustomOption onChange={() => {}} />' }, | |
].map(parserOptionsMapper), | |
invalid: [ | |
{ code: '<select onChange={() => {}} />;', errors: [expectedError] }, | |
{ code: '<select onChange={handleOnChange} />;', errors: [expectedError] }, | |
{ code: '<option onChange={() => {}} />', errors: [expectedError] }, | |
{ code: '<option onChange={() => {}} {...props} />', errors: [expectedError] }, | |
{ code: '<CustomOption onChange={() => {}} />;', errors: [expectedError], settings: componentsSettings }, | |
].map(parserOptionsMapper), | |
}); |