tests: add more route tests

This commit is contained in:
Douglas Christopher Wilson 2014-06-06 11:12:52 -04:00
parent 4279e6ef45
commit 21393c244c
3 changed files with 48 additions and 0 deletions

View File

@ -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);
});
})
})

View File

@ -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() {

View File

@ -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);
});
});