Skip to content

Commit 215de08

Browse files
committed
add tests
1 parent 351b449 commit 215de08

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/fittings/json_error_handler.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,39 @@ describe('json_error_handler', function() {
123123
});
124124
});
125125
});
126+
127+
describe('includeErrStack:true', function() {
128+
129+
var context;
130+
beforeEach(function() {
131+
var err = new Error('this is a test');
132+
err.statusCode = 401;
133+
err.someAttr = 'value';
134+
context = {
135+
headers: {},
136+
error: err
137+
};
138+
});
139+
140+
it('should allow the stack in the response body', function(done) {
141+
142+
var jsonErrorHandler = json_error_handler({ includeErrStack: true });
143+
144+
jsonErrorHandler(context, function(err, output) {
145+
should.not.exist(err);
146+
should.not.exist(context.error);
147+
148+
var e;
149+
try {
150+
var body = JSON.parse(output);
151+
body.should.have.property('message', 'this is a test');
152+
body.should.have.property('someAttr','value');
153+
body.should.have.property('stack')
154+
} catch(x) { e = x }
155+
done(e)
156+
});
157+
})
158+
})
126159

127160
describe('handle500Errors:true and error fails to stringify', function() {
128161
var jsonErrorHandler;

0 commit comments

Comments
 (0)