-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathheading-matches.js
More file actions
53 lines (44 loc) · 1.86 KB
/
heading-matches.js
File metadata and controls
53 lines (44 loc) · 1.86 KB
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
describe('heading-matches', function () {
'use strict';
const queryFixture = axe.testUtils.queryFixture;
const fixtureSetup = axe.testUtils.fixtureSetup;
let rule;
beforeEach(function () {
rule = axe.utils.getRule('empty-heading');
});
it('is a function', function () {
assert.isFunction(rule.matches);
});
it('should return false on elements that are not headings', function () {
const vNode = fixtureSetup('<div></div>');
assert.isFalse(rule.matches(null, vNode));
});
it('should return true on elements with role="heading"', function () {
const vNode = queryFixture('<div role="heading" id="target"></div>');
assert.isTrue(rule.matches(null, vNode));
});
it('should return true on regular headings without roles', function () {
for (let i = 1; i <= 6; i++) {
const vNode = queryFixture('<h' + i + ' id="target"></h' + i + '>');
assert.isTrue(rule.matches(null, vNode));
}
});
it('should return false on headings with their role changes', function () {
const vNode = queryFixture('<h1 role="banner" id="target"></h1>');
assert.isFalse(rule.matches(null, vNode));
});
it('should return true on headings with their role changes to an invalid role', function () {
const vNode = queryFixture('<h1 role="bruce" id="target"></h1>');
assert.isTrue(rule.matches(null, vNode));
});
it('should return true on headings with their role changes to an abstract role', function () {
const vNode = queryFixture('<h1 role="widget" id="target"></h1>');
assert.isTrue(rule.matches(null, vNode));
});
it('should return true on headings with explicit role="none" and an empty aria-label to account for presentation conflict resolution', function () {
const vNode = queryFixture(
'<h1 aria-label="" role="none" id="target"></h1>'
);
assert.isTrue(rule.matches(null, vNode));
});
});