forked from autocrypt/ui-autocrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.js
56 lines (48 loc) · 1.45 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
Tests = function() {
var env = {specs: {}, prefix: ''};
var assertions = 0;
var failures = 0;
function log(message) {
console.log( '%c ' + message, 'color: #444');
}
function fail(message) {
console.log( '%c ' + message, 'color: red');
}
function assert(truth, message) {
assertions = assertions + 1;
if (!truth) {
failures = failures + 1;
fail(" " + message);
}
};
assert.content = function(text, id) {
elem = document.getElementById(id);
assert( elem.innerText == text,
id + ' should contain "' + text + '".' );
};
function run() {
var arr = Object.entries(this.specs)
var setup = this.setup;
var teardown = this.teardown;
var prefix = this.prefix;
if (arr.length == 0) return;
arr.forEach(function (suite) {
var name = suite[0];
var desc = suite[1];
var env = {specs: {}, prefix: prefix + ' '};
log(prefix + name);
if (setup) setup();
desc.bind(env)(describe.bind(env), assert);
run.bind(env)();
if (teardown) teardown();
});
return (assertions + ' assertions. ' + failures + ' failures.');
};
function describe(context, fun) {
this.specs[context] = fun
};
return {
describe: describe.bind(env),
run: run.bind(env)
};
}();