Permalink
Cannot retrieve contributors at this time
56 lines (50 sloc)
2.43 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/accessible-emoji-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 <marquee> elements are not used. | |
* @author Ethan Cohen | |
*/ | |
// ----------------------------------------------------------------------------- | |
// Requirements | |
// ----------------------------------------------------------------------------- | |
import { RuleTester } from 'eslint'; | |
import parserOptionsMapper from '../../__util__/parserOptionsMapper'; | |
import rule from '../../../src/rules/accessible-emoji'; | |
// ----------------------------------------------------------------------------- | |
// Tests | |
// ----------------------------------------------------------------------------- | |
const ruleTester = new RuleTester(); | |
const expectedError = { | |
message: 'Emojis should be wrapped in <span>, have role="img", and have an accessible description with aria-label or aria-labelledby.', | |
type: 'JSXOpeningElement', | |
}; | |
ruleTester.run('accessible-emoji', rule, { | |
valid: [ | |
{ code: '<div />;' }, | |
{ code: '<span />' }, | |
{ code: '<span>No emoji here!</span>' }, | |
{ code: '<span role="img" aria-label="Panda face">🐼</span>' }, | |
{ code: '<span role="img" aria-label="Snowman">☃</span>' }, | |
{ code: '<span role="img" aria-labelledby="id1">🐼</span>' }, | |
{ code: '<span role="img" aria-labelledby="id1">☃</span>' }, | |
{ code: '<span role="img" aria-labelledby="id1" aria-label="Snowman">☃</span>' }, | |
{ code: '<span>{props.emoji}</span>' }, | |
{ code: '<span aria-hidden>{props.emoji}</span>' }, | |
{ code: '<span aria-hidden="true">🐼</span>' }, | |
{ code: '<span aria-hidden>🐼</span>' }, | |
{ code: '<div aria-hidden="true">🐼</div>' }, | |
{ code: '<input type="hidden">🐼</input>' }, | |
{ | |
code: '<CustomInput type="hidden">🐼</CustomInput>', | |
settings: { 'jsx-a11y': { components: { CustomInput: 'input' } } }, | |
}, | |
].map(parserOptionsMapper), | |
invalid: [ | |
{ code: '<span>🐼</span>', errors: [expectedError] }, | |
{ code: '<span>foo🐼bar</span>', errors: [expectedError] }, | |
{ code: '<span>foo 🐼 bar</span>', errors: [expectedError] }, | |
{ code: '<i role="img" aria-label="Panda face">🐼</i>', errors: [expectedError] }, | |
{ code: '<i role="img" aria-labelledby="id1">🐼</i>', errors: [expectedError] }, | |
{ code: '<Foo>🐼</Foo>', errors: [expectedError] }, | |
{ code: '<span aria-hidden="false">🐼</span>', errors: [expectedError] }, | |
{ code: '<CustomInput type="hidden">🐼</CustomInput>', errors: [expectedError] }, | |
].map(parserOptionsMapper), | |
}); |