-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathassertions.js
More file actions
57 lines (54 loc) · 1.36 KB
/
Copy pathassertions.js
File metadata and controls
57 lines (54 loc) · 1.36 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
/* globals $ */
function describe(description, descCB) {
if ($.writeln !== undefined) {
$.writeln(description);
}
descCB();
}
function test(description, testCB) {
try {
testCB();
if ($.writeln !== undefined) {
$.writeln("✓ " + description);
}
} catch (error) {
if ($.writeln !== undefined) {
$.writeln("✘ " + description);
$.writeln(error);
}
}
}
function expect(actual) {
return {
toBe: function(expected) {
if (actual !== expected) {
throw new Error(actual + " is not equal to " + expected);
}
},
toEqual: function(expected) {
if (actual !== expected) {
throw new Error(actual + " is not equal to " + expected);
}
},
toEqualArray: function(expected) {
if (Array.isArray(actual)) {
for(var i = 0; i < actual.length; ++i) {
if (actual[i] !== expected[i])
throw new Error(actual + " is not equal to " + expected);
}
} else {
throw new Error(actual + " is not equal to " + expected);
}
},
toBeGreaterThen: function(expected) {
if (actual <= expected) {
throw new Error(actual + " is not greater then " + expected);
}
},
toBeLessThen: function(expected) {
if (actual >= expected) {
throw new Error(actual + " is not less then " + expected);
}
}
};
}