Skip to content

Commit

Permalink
Add testing for errors thrown by express
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Loring committed Mar 15, 2016
1 parent fecb2f0 commit 0817cc8
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/hooks/test-trace-express.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,34 @@ describe('test-trace-express', function() {
});
});
});

it('should handle thrown errors from get', function(done) {
var app = express();
app.get('/', function(req, res) {
throw common.serverRes;
});
server = app.listen(common.serverPort, function() {
http.get({port: common.serverPort}, function(res) {
var labels = common.getMatchingSpan(expressPredicate).labels;
assert.equal(labels[traceLabels.HTTP_RESPONSE_CODE_LABEL_KEY], '500');
done();
});
});
});

it('should handle thrown errors from middleware', function(done) {
var app = express();
app.use(function(req, res, next) {
throw common.serverRes;
});
server = app.listen(common.serverPort, function() {
http.get({port: common.serverPort}, function(res) {
var labels = common.getMatchingSpan(expressPredicate).labels;
assert.equal(labels[traceLabels.HTTP_RESPONSE_CODE_LABEL_KEY], '500');
done();
});
});
});
});

function expressPredicate(span) {
Expand Down

0 comments on commit 0817cc8

Please sign in to comment.