From 21393c244cbcbbfe6d64a5252d1248875994efe0 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson <doug@somethingdoug.com> Date: Fri, 6 Jun 2014 11:12:52 -0400 Subject: [PATCH] tests: add more route tests --- test/Route.js | 19 +++++++++++++++++++ test/Router.js | 19 +++++++++++++++++++ test/app.route.js | 10 ++++++++++ 3 files changed, 48 insertions(+) diff --git a/test/Route.js b/test/Route.js index ccb102232fd..614947e9661 100644 --- a/test/Route.js +++ b/test/Route.js @@ -167,5 +167,24 @@ describe('Route', function(){ route.dispatch({ method: 'get' }, {}); }); + + it('should handle throwing inside error handlers', function(done) { + var route = new Route(''); + + route.get(function(req, res, next){ + throw new Error('boom!'); + }); + + route.get(function(err, req, res, next){ + throw new Error('oops'); + }); + + route.get(function(err, req, res, next){ + assert.equal(err.message, 'oops'); + done(); + }); + + route.dispatch({ url: '/', method: 'GET' }, {}, done); + }); }) }) diff --git a/test/Router.js b/test/Router.js index 0a84a88c117..a1fc89ecee9 100644 --- a/test/Router.js +++ b/test/Router.js @@ -131,6 +131,25 @@ describe('Router', function(){ router.handle({ url: '/foo/2', method: 'GET' }, {}, done); }); + + it('should handle throwing inside error handlers', function(done) { + var router = new Router(); + + router.use(function(req, res, next){ + throw new Error('boom!'); + }); + + router.use(function(err, req, res, next){ + throw new Error('oops'); + }); + + router.use(function(err, req, res, next){ + assert.equal(err.message, 'oops'); + done(); + }); + + router.handle({ url: '/', method: 'GET' }, {}, done); + }); }) describe('.all', function() { diff --git a/test/app.route.js b/test/app.route.js index 8675b4e184b..75e5e0b8421 100644 --- a/test/app.route.js +++ b/test/app.route.js @@ -49,4 +49,14 @@ describe('app.route', function(){ .get('/test') .expect('test', done); }); + + it('should not error on empty routes', function(done){ + var app = express(); + + app.route('/:foo'); + + request(app) + .get('/test') + .expect(404, done); + }); });