Permalink
Cannot retrieve contributors at this time
50 lines (44 sloc)
1.62 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/anchor-has-content-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 anchor elements to contain accessible content. | |
* @author Lisa Ring & Niklas Holmberg | |
*/ | |
// ----------------------------------------------------------------------------- | |
// Requirements | |
// ----------------------------------------------------------------------------- | |
import { RuleTester } from 'eslint'; | |
import parserOptionsMapper from '../../__util__/parserOptionsMapper'; | |
import rule from '../../../src/rules/anchor-has-content'; | |
// ----------------------------------------------------------------------------- | |
// Tests | |
// ----------------------------------------------------------------------------- | |
const ruleTester = new RuleTester(); | |
const expectedError = { | |
message: 'Anchors must have content and the content must be accessible by a screen reader.', | |
type: 'JSXOpeningElement', | |
}; | |
ruleTester.run('anchor-has-content', rule, { | |
valid: [ | |
{ code: '<div />;' }, | |
{ code: '<a>Foo</a>' }, | |
{ code: '<a><Bar /></a>' }, | |
{ code: '<a>{foo}</a>' }, | |
{ code: '<a>{foo.bar}</a>' }, | |
{ code: '<a dangerouslySetInnerHTML={{ __html: "foo" }} />' }, | |
{ code: '<a children={children} />' }, | |
{ code: '<Link />' }, | |
{ | |
code: '<Link>foo</Link>', | |
settings: { 'jsx-a11y': { components: { Link: 'a' } } }, | |
}, | |
].map(parserOptionsMapper), | |
invalid: [ | |
{ code: '<a />', errors: [expectedError] }, | |
{ code: '<a><Bar aria-hidden /></a>', errors: [expectedError] }, | |
{ code: '<a>{undefined}</a>', errors: [expectedError] }, | |
{ | |
code: '<Link />', | |
errors: [expectedError], | |
settings: { 'jsx-a11y': { components: { Link: 'a' } } }, | |
}, | |
].map(parserOptionsMapper), | |
}); |