Skip to content

Commit

Permalink
test(server): add _routeErrorResponse avoiding uncaughtException by o…
Browse files Browse the repository at this point in the history
…nly sending response when not sent test from #1568
  • Loading branch information
hekike committed Nov 21, 2017
1 parent 8e1f0d0 commit 23b2aed
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/server.test.js
Expand Up @@ -202,6 +202,34 @@ test('rm', function(t) {
});
});

test(
'_routeErrorResponse does not cause uncaughtException when called when' +
'header has already been sent',
function(t) {
SERVER.on('MethodNotAllowed', function(req, res, error, next) {
res.json(405, { status: 'MethodNotAllowed' });
try {
next();
} catch (err) {
t.fail(
'next() should not throw error' +
'when header has already been sent'
);
}
t.end();
});

SERVER.post('/routePostOnly', function tester(req, res, next) {
next();
});

CLIENT.get('/routePostOnly', function(err, _, res) {
t.ok(err);
t.equal(res.statusCode, 405);
});
}
);

test('use - throws TypeError on non function as argument', function(t) {
var errMsg = 'handler (function) is required';

Expand Down

0 comments on commit 23b2aed

Please sign in to comment.