-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtests.js
100 lines (85 loc) · 2.36 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
98
99
100
var vows = require('vows');
var assert = require('assert');
var ERR = require("./ERR");
var emptyFunc = function(){};
vows.describe('ERR function').addBatch({
'when its loaded' : {
topic: function() {
return require("./ERR");
},
'it returns the ERR function': function(topic){
assert.equal(typeof topic, "function");
},
'its not global': function(topic){
assert.isUndefined(global.ERR);
}
}
}).addBatch({
'when you call it without an error' : {
'it returns false' : function() {
assert.isFalse(ERR());
}
},
'when you call it with an error' : {
'it returns true' : function() {
assert.isTrue(ERR(new Error(), emptyFunc));
}
},
'when you give it a callback and an error': {
'it calls the callback with the error' : function() {
ERR(new Error(), function(err) {
assert.isNotNull(err);
});
}
},
'when you give it no callback and an error': {
'it throws the error' : function() {
var wasThrown = false;
try
{
ERR(new Error());
}
catch(e)
{
wasThrown = true;
}
assert.isTrue(wasThrown);
}
},
'when you call it with a string as an error' : {
'it uses the string as an error message' : function(){
var errStr = "testerror";
var err;
ERR(errStr, function(_err){
err = _err;
});
assert.equal(err.message, errStr);
}
},
'when you give it a non-async stacktrace': {
'it turns it into an async stacktrace' : function(){
var errorBefore = new Error();
var stackLinesBefore = errorBefore.stack.split("\n").length;
var errorAfter;
ERR(errorBefore, function(err){
errorAfter = err;
});
var stackLinesAfter = errorAfter.stack.split("\n").length;
assert.equal(stackLinesBefore+3, stackLinesAfter);
}
},
'when you give it a async stacktrace': {
'it adds a new stack line' : function(){
var err = new Error();
ERR(err, function(_err){
err = _err;
});
var stackLinesBefore = err.stack.split("\n").length;
ERR(err, function(_err){
err = _err;
});
var stackLinesAfter = err.stack.split("\n").length;
assert.equal(stackLinesBefore+1, stackLinesAfter);
}
}
}).run();