-
-
Notifications
You must be signed in to change notification settings - Fork 637
/
iframe-has-title-test.js
55 lines (48 loc) · 2.02 KB
/
iframe-has-title-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* @fileoverview Enforce iframe elements have a title attribute.
* @author Ethan Cohen
*/
// -----------------------------------------------------------------------------
// Requirements
// -----------------------------------------------------------------------------
import { RuleTester } from 'eslint';
import parserOptionsMapper from '../../__util__/parserOptionsMapper';
import parsers from '../../__util__/helpers/parsers';
import rule from '../../../src/rules/iframe-has-title';
// -----------------------------------------------------------------------------
// Tests
// -----------------------------------------------------------------------------
const ruleTester = new RuleTester();
const expectedError = {
message: '<iframe> elements must have a unique title property.',
type: 'JSXOpeningElement',
};
const componentsSettings = {
'jsx-a11y': {
components: {
FooComponent: 'iframe',
},
},
};
ruleTester.run('html-has-lang', rule, {
valid: parsers.all([].concat(
{ code: '<div />;' },
{ code: '<iframe title="Unique title" />' },
{ code: '<iframe title={foo} />' },
{ code: '<FooComponent />' },
{ code: '<FooComponent title="Unique title" />', settings: componentsSettings },
)).map(parserOptionsMapper),
invalid: parsers.all([].concat(
{ code: '<iframe />', errors: [expectedError] },
{ code: '<iframe {...props} />', errors: [expectedError] },
{ code: '<iframe title={undefined} />', errors: [expectedError] },
{ code: '<iframe title="" />', errors: [expectedError] },
{ code: '<iframe title={false} />', errors: [expectedError] },
{ code: '<iframe title={true} />', errors: [expectedError] },
{ code: "<iframe title={''} />", errors: [expectedError] },
{ code: '<iframe title={``} />', errors: [expectedError] },
{ code: '<iframe title={""} />', errors: [expectedError] },
{ code: '<iframe title={42} />', errors: [expectedError] },
{ code: '<FooComponent />', errors: [expectedError], settings: componentsSettings },
)).map(parserOptionsMapper),
});