Skip to content

Commit

Permalink
fix(conditional): Allow additional arguments to be used in conditiona…
Browse files Browse the repository at this point in the history
…l functions (#57)
  • Loading branch information
elliotttf committed Jan 10, 2018
1 parent fa02fc6 commit eca21f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/conditional.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const once = require('once');
*/
module.exports = (condition, success, fail) => (req, res, next, ...rest) => {
const nextOnce = once(next);
if (condition === true || (typeof condition === 'function' && condition(req, res, nextOnce))) {
if (condition === true || (typeof condition === 'function' && condition(req, res, nextOnce, ...rest))) {
return success(req, res, nextOnce, ...rest);
}
if (fail) {
Expand Down
11 changes: 11 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ module.exports = {
});
},

funcAdditional(test) {
const conditionFunc = (req, res, next, extra) => extra === true;

const middleware = conditional(conditionFunc, (req, res, next) => {
test.ok(true, 'Conditional function returned true.');
next();
});

middleware({ working: true }, {}, () => test.done(), true);
},

funcOnce(test) {
test.expect(2);

Expand Down

0 comments on commit eca21f3

Please sign in to comment.