refactor routes.error tests

This commit is contained in:
TJ Holowaychuk
2012-10-09 19:09:12 -07:00
parent 78d5b72081
commit 0dd80e7b50

View File

@@ -6,27 +6,33 @@ describe('app', function(){
it('should only call an error handling routing callback when an error is propagated', function(done){
var app = express();
var a = false;
var b = false;
var c = false;
var d = false;
app.get('/', function(req, res, next){
req.thruSecondCallback = false;
req.thruThirdCallback = false;
req.thruFourthCallback = false;
next(new Error('fabricated error'));
}, function(req, res, next) {
req.thruSecondCallback = true;
a = true;
next();
}, function(err, req, res, next){
b = true;
err.message.should.equal('fabricated error');
next(err);
}, function(err, req, res, next){
c = true;
err.message.should.equal('fabricated error');
req.thruThirdCallback = true;
next();
}, function(err, req, res, next){
req.thruFourthCallback = true;
d = true;
next();
}, function(req, res){
req.thruSecondCallback.should.equal(false);
req.thruThirdCallback.should.equal(true);
req.thruFourthCallback.should.equal(false);
res.status(204);
res.end();
a.should.be.false;
b.should.be.true;
c.should.be.true;
d.should.be.false;
res.send(204);
});
request(app)