Skip to content

Commit

Permalink
tests: add more route tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Jun 6, 2014
1 parent 4279e6e commit 21393c2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/Route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
})
})
19 changes: 19 additions & 0 deletions test/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
10 changes: 10 additions & 0 deletions test/app.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 21393c2

Please sign in to comment.