-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhtml-namespace-matches.js
More file actions
79 lines (67 loc) · 2.49 KB
/
html-namespace-matches.js
File metadata and controls
79 lines (67 loc) · 2.49 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
describe('html-namespace-matches', function () {
'use strict';
let rule;
let fixture;
let axeFixtureSetup;
beforeEach(function () {
fixture = document.getElementById('fixture');
axeFixtureSetup = axe.testUtils.fixtureSetup;
rule = axe.utils.getRule('role-img-alt');
});
afterEach(function () {
fixture.innerHTML = '';
});
it('returns true when passed an HTML element', function () {
axeFixtureSetup('<h1>Hello world</h1>');
const node = fixture.querySelector('h1');
const virtualNode = axe.utils.getNodeFromTree(axe._tree[0], node);
assert.isTrue(rule.matches(node, virtualNode));
});
it('returns true when passed a custom HTML element', function () {
axeFixtureSetup('<xx-heading>Hello world</xx-heading>');
const node = fixture.querySelector('xx-heading');
const virtualNode = axe.utils.getNodeFromTree(axe._tree[0], node);
assert.isTrue(rule.matches(node, virtualNode));
});
it('returns false when passed an SVG element', function () {
axeFixtureSetup('<svg><title>Pretty picture</title></svg>');
const node = fixture.querySelector('svg');
const virtualNode = axe.utils.getNodeFromTree(axe._tree[0], node);
assert.isFalse(rule.matches(node, virtualNode));
});
it('returns false when passed an SVG circle element', function () {
axeFixtureSetup(
'<svg><circle><title>Pretty picture</title></circle></svg>'
);
const node = fixture.querySelector('circle');
const virtualNode = axe.utils.getNodeFromTree(axe._tree[0], node);
assert.isFalse(rule.matches(node, virtualNode));
});
describe('Serial Virtual Node', function () {
it('returns true when passed an HTML element', function () {
const serialNode = new axe.SerialVirtualNode({
nodeName: 'h1'
});
serialNode.parent = null;
assert.isTrue(rule.matches(null, serialNode));
});
it('returns true when passed a custom HTML element', function () {
const serialNode = new axe.SerialVirtualNode({
nodeName: 'xx-heading'
});
serialNode.parent = null;
assert.isTrue(rule.matches(null, serialNode));
});
it('returns false when passed an SVG circle element', function () {
const serialNode = new axe.SerialVirtualNode({
nodeName: 'circle'
});
const parent = new axe.SerialVirtualNode({
nodeName: 'svg'
});
serialNode.parent = parent;
parent.children = [serialNode];
assert.isFalse(rule.matches(null, serialNode));
});
});
});