-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathskip-link-matches.js
More file actions
59 lines (48 loc) · 1.62 KB
/
skip-link-matches.js
File metadata and controls
59 lines (48 loc) · 1.62 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
describe('skip-link-matches', function () {
'use strict';
let rule, link;
const fixture = document.getElementById('fixture');
beforeEach(function () {
rule = axe.utils.getRule('skip-link');
fixture.innerHTML =
'<a href="" id="target" style="position: absolute; left: -10000px;">Click me</a><div id="main"></div>';
link = fixture.querySelector('#target');
axe._tree = axe.utils.getFlattenedTree(fixture);
});
afterEach(function () {
fixture.innerHTML = '';
axe._tree = undefined;
});
it('is a function', function () {
assert.isFunction(rule.matches);
});
it('returns false if the links is onscreen', function () {
link.removeAttribute('style');
link.href = '#main';
assert.isFalse(rule.matches(link));
});
it('returns false if the href attribute does not start with #', function () {
link.href = 'foo#bar';
assert.isFalse(rule.matches(link));
});
it('returns false if the href attribute is `#`', function () {
link.href = '#';
assert.isFalse(rule.matches(link));
});
it('returns false if the href attribute starts with #!', function () {
link.href = '#!foo';
assert.isFalse(rule.matches(link));
});
it('returns false if the href attribute starts with #/', function () {
link.href = '#/foo';
assert.isFalse(rule.matches(link));
});
it('returns true if the href attribute starts with #', function () {
link.href = '#main';
assert.isTrue(rule.matches(link));
});
it('returns true if the href attribute starts with /# (angular)', function () {
link.href = '/#main';
assert.isTrue(rule.matches(link));
});
});