diff --git a/lib/ConnectSequence.js b/lib/ConnectSequence.js index 3bf43bf..ac8a3e7 100644 --- a/lib/ConnectSequence.js +++ b/lib/ConnectSequence.js @@ -147,6 +147,7 @@ function append (/* mid_0, ..., mid_n */) { for (i = 0; i < arguments.length; i++) { this.middlewares.push(arguments[i]) } + return this } /** @@ -189,7 +190,7 @@ function appendIf (filter, middleware) { } if (isErrorHandler(middleware)) { - this.append(function (err, req, res, next) { + return this.append(function (err, req, res, next) { if (filter(req)) { middleware(err, req, res, next) return @@ -199,7 +200,7 @@ function appendIf (filter, middleware) { } }) } else { - this.append(function (req, res, next) { + return this.append(function (req, res, next) { if (filter(req)) { middleware(req, res, next) return diff --git a/tests/ConnectSequence.spec.js b/tests/ConnectSequence.spec.js index 4d85aae..245d9d6 100644 --- a/tests/ConnectSequence.spec.js +++ b/tests/ConnectSequence.spec.js @@ -269,6 +269,11 @@ describe('ConnectSequence', function () { }) describe('#append()', function () { + it('should be chainable', function () { + seq = new ConnectSequence(req, res, next) + expect(seq.append(mid)).to.equal(seq) + }) + it('should augments the length of the middlewares array by the number of given middlewares', function () { seq = new ConnectSequence(req, res, next) var mid = function (req, res, next) { next() } @@ -324,6 +329,11 @@ describe('ConnectSequence', function () { }) describe('#appendList()', function () { + it('should be chainable', function () { + seq = new ConnectSequence(req, res, next) + expect(seq.appendList([mid])).to.equal(seq) + }) + it('should throw TypeError if the first argument is not an array', function () { var funcs = [ function () { @@ -405,6 +415,11 @@ describe('ConnectSequence', function () { filter = function (req) { return !!req.foo } }) + it('should be chainable', function () { + seq = new ConnectSequence(req, res, next) + expect(seq.appendIf(filter, mid)).to.equal(seq) + }) + it('should throw `MissingArgumentError` if called with lower than 2 arguments', function () { expect(function () { seq.appendIf()