Skip to content

Commit

Permalink
pass initial next function through
Browse files Browse the repository at this point in the history
  • Loading branch information
calebboyd committed Sep 25, 2015
1 parent 8b84aca commit 1c9c3d1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function tryCatch(fn, ctx, next) {

function middlewareReducer(next, mw) {
return function(ctx, nextFn) {
ctx.next = next && function () { return next(ctx) }
ctx.next = next && function () { return next(ctx, nextFn) }
|| nextFn
|| noop
return tryCatch(mw, ctx, ctx.next)
Expand Down
22 changes: 22 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,28 @@ describe('Koa Compose', function(){
})
})

it('should return a valid middleware', function () {
var val = 0
compose([
compose([
(ctx, next) => {
val++
return next()
},
(ctx, next) => {
val++
return next()
}
]),
(ctx, next) => {
val++
return next()
}
])({}).then(function () {
val.should.equal(3)
})
})

it('should expose next on the context', function () {
var stack = [];

Expand Down

0 comments on commit 1c9c3d1

Please sign in to comment.