diff --git a/index.js b/index.js index 48dbfb6..d672cd9 100644 --- a/index.js +++ b/index.js @@ -149,6 +149,12 @@ Kareem.prototype.execPost = function(name, context, args, options, callback) { next(); } } else { + if (post.length === args.length + 2) { + if (++currentPost >= numPosts) { + return callback.apply(null, [null].concat(args)); + } + next(); + } if (post.length === args.length + 1) { post.apply(context, args.concat(function(error) { if (error) { diff --git a/test/wrap.test.js b/test/wrap.test.js index b3f9a7a..b3fe7d0 100644 --- a/test/wrap.test.js +++ b/test/wrap.test.js @@ -174,6 +174,27 @@ describe('wrap()', function() { { useErrorHandlers: true }); }); + it('error handlers with no error', function(done) { + hooks.post('cook', function(error, callback) { + callback(new Error('another error occurred')); + }); + + var args = []; + args.push(function(error) { + assert.ifError(error); + done(); + }); + + hooks.wrap( + 'cook', + function(callback) { + callback(); + }, + null, + args, + { useErrorHandlers: true }); + }); + it('works with no args', function(done) { hooks.pre('cook', function(done) { done();