Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/ConnectSequence.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ function append (/* mid_0, ..., mid_n */) {
for (i = 0; i < arguments.length; i++) {
this.middlewares.push(arguments[i])
}
return this
}

/**
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
15 changes: 15 additions & 0 deletions tests/ConnectSequence.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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()
Expand Down