-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlink-in-text-block-matches.js
More file actions
80 lines (71 loc) · 2.54 KB
/
link-in-text-block-matches.js
File metadata and controls
80 lines (71 loc) · 2.54 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
80
describe('link-in-text-block-matches', () => {
const { fixtureSetup } = axe.testUtils;
const rule = axe.utils.getRule('link-in-text-block');
it('should return true if link is in text block', () => {
fixtureSetup(
'<p>Some paragraph with text <a id="target" href="#">world</a></p>'
);
const node = document.getElementById('target');
assert.isTrue(rule.matches(node));
});
it('should return false if element has a non-link role', () => {
fixtureSetup(
'<p>Some paragraph with text <a id="target" href="#" role="button">hello</a></p>'
);
const node = document.getElementById('target');
assert.isFalse(rule.matches(node));
});
it('should should return false if element does not have text', () => {
fixtureSetup(
'<p>Some paragraph with text <a id="target" href="#"></a></p>'
);
const node = document.getElementById('target');
assert.isFalse(rule.matches(node));
});
it('should return false if element has <style>', () => {
fixtureSetup(`
<p>Some paragraph with text
<a id="target" href="#">
<style>a { color: #333 }</style>
</a>
</p>
`);
const node = document.getElementById('target');
assert.isFalse(rule.matches(node));
});
it('should return false if element has <script>', () => {
fixtureSetup(`
<p>Some paragraph with text
<a id="target" href="#">
<script>console.log('foo')</script>
</a>
</p>
`);
const node = document.getElementById('target');
assert.isFalse(rule.matches(node));
});
it('should return false if element is hidden', () => {
fixtureSetup(
'<p>Some paragraph with text <a id="target" href="#"" style="display: none">hello</a></p>'
);
const node = document.getElementById('target');
assert.isFalse(rule.matches(node));
});
it('should return false if link is not in text block', () => {
fixtureSetup('<a id="target" href="#">hello</a>');
const node = document.getElementById('target');
assert.isFalse(rule.matches(node));
});
it('should return false if link is only text in block', () => {
fixtureSetup('<p><a id="target" href="#">world</a></p>');
const node = document.getElementById('target');
assert.isFalse(rule.matches(node));
});
it('should return false if link is display block', () => {
fixtureSetup(
'<p>Some paragraph with text <a id="target" href="#" style="display: block">world</a></p>'
);
const node = document.getElementById('target');
assert.isFalse(rule.matches(node));
});
});