From aa92412db32cf437c9fcecbd1c076b1b6e8e6d3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Wed, 12 Nov 2014 10:09:20 +0100 Subject: [PATCH] app.middleware: verify serial exec of handlers Add a test verifying that middleware handlers are executed serially. --- test/app.test.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/app.test.js b/test/app.test.js index 18ab3cbc..7223b118 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -85,6 +85,30 @@ describe('app', function() { }); }); + it('passes errors to error handlers in the same phase', function(done) { + var expectedError = new Error('this should be handled by middleware'); + var handledError; + + app.middleware('initial', function(req, res, next) { + // continue in the next tick, this verifies that the next + // handler waits until the previous one is done + process.nextTick(function() { + next(expectedError); + }); + }); + + app.middleware('initial', function(err, req, res, next) { + handledError = err; + next(); + }); + + executeMiddlewareHandlers(app, function(err) { + if (err) return done(err); + expect(handledError).to.equal(expectedError); + done(); + }); + }); + function namedHandler(name) { return function(req, res, next) { steps.push(name);