-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
test.js
78 lines (59 loc) · 1.65 KB
/
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import test from 'tape';
import select from '.';
document.body.innerHTML = `
<ul>
<li>Foo</li>
<li>Bar</li>
<li>Qux</li>
</ul>
<ul>
<li>Lorem</li>
<li>Ipsum</li>
</ul>
`;
test('selects one element', t => {
t.plan(1);
const li = document.querySelector('ul li');
t.equal(select('ul li'), li);
});
test('selects one element within an ancestor', t => {
t.plan(1);
const li = document.querySelector('ul li');
t.equal(select('li', select('ul')), li);
});
test('selects the last element', t => {
t.plan(1);
const li = [...document.querySelectorAll('ul li')].pop();
t.equal(select.last('ul li'), li);
});
test('selects the last element within an ancestor', t => {
t.plan(1);
const li = [...document.querySelectorAll('ul li')].pop();
t.equal(select.last('li', select.last('ul')), li);
});
test('tests existence of one element', t => {
t.plan(2);
t.true(select.exists('ul li'));
t.false(select.exists('lololol'));
});
test('tests existence of one element within an ancestor', t => {
t.plan(3);
t.true(select.exists('li', select('ul')));
t.false(select.exists('ul', select('li')));
t.false(select.exists('ul', select('lololol')));
});
test('selects all elements', t => {
t.plan(1);
const li = document.querySelectorAll('ul li');
t.deepEqual(select.all('ul li'), li);
});
test('selects all elements within an ancestor', t => {
t.plan(1);
const li = document.querySelector('ul').querySelectorAll('ul li');
t.deepEqual(select.all('li', select('ul')), li);
});
test('selects all elements within an array of ancestors', t => {
t.plan(1);
const li = document.querySelectorAll('ul li');
t.deepEqual(select.all('li', select.all('ul')), li);
});