-
-
Notifications
You must be signed in to change notification settings - Fork 233
/
Copy pathtests.js
97 lines (77 loc) · 2.12 KB
/
tests.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
QUnit.module("classList.toggle");
QUnit.test("Adds a class", function(assert) {
var cList = document.createElement("p").classList;
cList.toggle("c1");
assert.ok(cList.contains("c1"), "Adds a class that is not present");
assert.strictEqual(
cList.toggle("c2"),
true,
"Returns true when class is added"
);
});
QUnit.test("Removes a class", function(assert) {
var cList = document.createElement("p").classList;
cList.add("c1");
cList.toggle("c1");
assert.ok(!cList.contains("c1"), "Removes a class that is present");
cList.add("c2");
assert.strictEqual(
cList.toggle("c2"),
false,
"Return false when class is removed"
);
});
QUnit.test("Adds class with second argument", function(assert) {
var cList = document.createElement("p").classList;
cList.toggle("c1", true);
assert.ok(cList.contains("c1"), "Adds a class");
assert.strictEqual(
cList.toggle("c2", true),
true,
"Returns true when class is added"
);
cList.add("c3");
cList.toggle("c3", true);
assert.ok(
cList.contains("c3"),
"Does not remove a class that is already present"
);
cList.add("c4");
assert.strictEqual(
cList.toggle("c4", true),
true,
"Returns true when class is already present"
);
});
QUnit.test("Removes class with second argument", function(assert) {
var cList = document.createElement("p").classList;
cList.add("c1");
cList.toggle("c1", false);
assert.ok(!cList.contains("c1"), "Removes a class");
assert.strictEqual(
cList.toggle("c2", false),
false,
"Returns false when class is removed"
);
cList.toggle("c3", false);
assert.ok(
!cList.contains("c3"),
"Does not add a class that is not present"
);
assert.strictEqual(
cList.toggle("c4", false),
false,
"Returns false when class was not present"
);
});
QUnit.test("Adds no class with no argument", function(assert) {
var cList = document.createElement("p").classList;
cList.add();
assert.ok(!cList.contains("c1"), "Adds no class");
});
QUnit.test("Removes no class with no argument", function(assert) {
var cList = document.createElement("p").classList;
cList.add("c1");
cList.remove();
assert.ok(cList.contains("c1"), "Removes no class");
});