forked from tidev/node-appc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-exception.js
More file actions
157 lines (144 loc) · 3.73 KB
/
test-exception.js
File metadata and controls
157 lines (144 loc) · 3.73 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* node-appc - Appcelerator Common Library for Node.js
* Copyright (c) 2009-2014 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
var appc = require('../index'),
AppcException = appc.exception;
describe('exception', function () {
it('namespace exists', function () {
appc.should.have.property('exception');
appc.exception.should.be.a.Function;
});
it('should have a type', function () {
try {
throw new AppcException;
} catch (ex) {
ex.should.have.property('type');
ex.type.should.equal('AppcException');
}
});
it('should have an empty message', function () {
try {
throw new AppcException;
} catch (ex) {
ex.should.have.property('type');
ex.type.should.equal('AppcException');
ex.should.have.property('message');
ex.message.should.equal('');
ex.should.have.property('details');
ex.details.should.eql([]);
}
});
it('should have a message', function () {
try {
throw new AppcException('whoops');
} catch (ex) {
ex.should.have.property('type');
ex.type.should.equal('AppcException');
ex.should.have.property('message');
ex.message.should.equal('whoops');
ex.should.have.property('details');
ex.details.should.eql([]);
}
});
it('should have a message and some error details', function () {
try {
throw new AppcException('whoops', [ 'detail 1', 'detail 2' ]);
} catch (ex) {
ex.should.have.property('type');
ex.type.should.equal('AppcException');
ex.should.have.property('message');
ex.message.should.equal('whoops');
ex.should.have.property('details');
ex.details.should.eql([ 'detail 1', 'detail 2' ]);
}
});
it('#log()', function () {
try {
var err = new AppcException('whoops');
err.log('detail 1');
err.log('detail 2');
throw err;
} catch (ex) {
ex.should.have.property('type');
ex.type.should.equal('AppcException');
ex.should.have.property('message');
ex.message.should.equal('whoops');
ex.should.have.property('details');
ex.details.should.eql([ 'detail 1', 'detail 2' ]);
}
});
it('#dump() with function', function () {
try {
throw new AppcException('whoops', [ 'detail 1', 'detail 2' ]);
} catch (ex) {
var buffer = '';
function logger(s) {
buffer += s + '\n';
}
ex.dump(logger);
buffer.should.equal('whoops\ndetail 1\ndetail 2\n');
}
});
it('#dump() with object', function () {
try {
throw new AppcException('whoops', [ 'detail 1', 'detail 2' ]);
} catch (ex) {
var buffer = '';
function logger(s) {
buffer += s + '\n';
}
ex.dump({
log: logger,
error: logger
});
buffer.should.equal('whoops\ndetail 1\ndetail 2\n');
}
});
it('#dump() with object.log()', function () {
try {
throw new AppcException('whoops', [ 'detail 1', 'detail 2' ]);
} catch (ex) {
var buffer = '';
function logger(s) {
buffer += s + '\n';
}
ex.dump({
log: logger
});
buffer.should.equal('whoops\ndetail 1\ndetail 2\n');
}
});
it('#dump() with object.error()', function () {
try {
throw new AppcException('whoops', [ 'detail 1', 'detail 2' ]);
} catch (ex) {
var buffer = '';
function logger(s) {
buffer += s + '\n';
}
ex.dump({
error: logger
});
buffer.should.equal('whoops\ndetail 1\ndetail 2\n');
}
});
it('#dump() with bad object', function () {
try {
throw new AppcException('whoops', [ 'detail 1', 'detail 2' ]);
} catch (ex) {
(function () {
ex.dump({});
}).should.throw();
}
});
it('#toString()', function () {
try {
throw new AppcException('whoops', [ 'detail 1', 'detail 2' ]);
} catch (ex) {
ex.toString().should.equal('whoops\ndetail 1\ndetail 2');
}
});
});