Skip to content

Commit 7d3c8b1

Browse files
committed
adds test for svg-has-accessible-name rule
1 parent c916e88 commit 7d3c8b1

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/a11y-svg-has-accessible-name.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const rule = require('../lib/rules/a11y-svg-has-accessible-name')
2+
const RuleTester = require('eslint').RuleTester
3+
4+
const ruleTester = new RuleTester({
5+
parserOptions: {
6+
ecmaVersion: 'latest',
7+
sourceType: 'module',
8+
ecmaFeatures: {
9+
jsx: true,
10+
},
11+
},
12+
})
13+
14+
const errorMessage =
15+
'SVG elements should have an accessible name. Add a `<title>` element as the first descendant of the `<svg>` or add an `aria-label` or `aria-labelledby` to the `<svg>` element.'
16+
17+
ruleTester.run('a11y-aria-label-is-well-formatted', rule, {
18+
valid: [
19+
{code: "<svg height='100' width='100'><title>Circle with a black outline and red fill</title><circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red'/></svg>"},
20+
{code: "<svg aria-label='Circle with a black outline and red fill' height='100' width='100'><circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red'/></svg>"},
21+
{code: "<svg aria-labelledby='circle_text' height='100' width='100'><circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red'/></svg>"},
22+
],
23+
invalid: [
24+
{code: "<svg height='100' width='100'><circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red'/></svg>;", errors: [{message: errorMessage}]},
25+
],
26+
})

0 commit comments

Comments
 (0)