Skip to content

Commit

Permalink
Fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed May 4, 2015
1 parent 23fa74c commit de60dc6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
14 changes: 10 additions & 4 deletions index.js
Expand Up @@ -38,7 +38,7 @@ Kareem.prototype.execPre = function(name, context, callback) {
}

++currentPre;
next();
next.apply(context, arguments);
},
function(error) {
if (error) {
Expand All @@ -54,7 +54,7 @@ Kareem.prototype.execPre = function(name, context, callback) {
}
});
} else if (pre.fn.length > 0) {
pre.fn.call(context, function(error) {
var args = [function(error) {
if (error) {
if (done) {
return;
Expand All @@ -72,8 +72,14 @@ Kareem.prototype.execPre = function(name, context, callback) {
}
}

next();
});
next.apply(context, arguments);
}];
if (arguments.length >= 2) {
for (var i = 1; i < arguments.length; ++i) {
args.push(arguments[i]);
}
}
pre.fn.apply(context, args);
} else {
pre.fn.call(context);
if (++currentPre >= numPres) {
Expand Down
30 changes: 30 additions & 0 deletions test/pre.test.js
Expand Up @@ -193,4 +193,34 @@ describe('execPre', function() {
done();
});
});

it('allows passing arguments to the next pre', function(done) {
var execed = {};

hooks.pre('cook', function(next) {
execed.first = true;
next(null, 'test');
});

hooks.pre('cook', function(next, p) {
execed.second = true;
assert.equal(p, 'test');
next();
});

hooks.pre('cook', function(next, p) {
execed.third = true;
assert.ok(!p);
next();
});

hooks.execPre('cook', null, function(err) {
assert.ifError(err);
assert.equal(3, Object.keys(execed).length);
assert.ok(execed.first);
assert.ok(execed.second);
assert.ok(execed.third);
done();
});
});
});

0 comments on commit de60dc6

Please sign in to comment.