Permalink
Browse files

Merge pull request #6 from aheckmann/ignoreUndefined

treat undefined the same as null
  • Loading branch information...
2 parents f778859 + d47a376 commit 89d472a6a871d22aab81aa6f076556d6c03a1aae @bnoguchi committed Apr 17, 2012
Showing with 9 additions and 3 deletions.
  1. +1 −1 hooks.js
  2. +8 −2 test.js
View
@@ -36,7 +36,7 @@ module.exports = {
var _args = Array.prototype.slice.call(arguments)
, currPre
, preArgs;
- if (_args.length && !(arguments[0] === null && typeof lastArg === 'function'))
+ if (_args.length && !(arguments[0] == null && typeof lastArg === 'function'))
hookArgs = _args;
if (++_current < _total) {
currPre = pres[_current]
View
10 test.js
@@ -267,7 +267,7 @@ module.exports = {
}
didCatch.should.be.true;
},
- "should proceed without mutating arguments if `next(null)` is called in a serial pre, and the last argument of the target method is a callback with node-like signature function (err, obj) {...} or function (err) {...}": function () {
+ "should proceed without mutating arguments if `next(null|undefined)` is called in a serial pre, and the last argument of the target method is a callback with node-like signature function (err, obj) {...} or function (err) {...}": function () {
var A = function () {};
_.extend(A, hooks);
var counter = 0;
@@ -278,6 +278,9 @@ module.exports = {
A.pre('save', function (next) {
next(null);
});
+ A.pre('save', function (next) {
+ next(undefined);
+ });
var a = new A();
a.save( function (err) {
if (err instanceof Error) counter++;
@@ -286,13 +289,16 @@ module.exports = {
counter.should.equal(-1);
a.value.should.eql(1);
},
- "should proceed with mutating arguments if `next(null)` is callback in a serial pre, and the last argument of the target method is not a function": function () {
+ "should proceed with mutating arguments if `next(null|undefined)` is callback in a serial pre, and the last argument of the target method is not a function": function () {
var A = function () {};
_.extend(A, hooks);
A.prototype.set = function (v) {
this.value = v;
};
A.pre('set', function (next) {
+ next(undefined);
+ });
+ A.pre('set', function (next) {
next(null);
});
var a = new A();

0 comments on commit 89d472a

Please sign in to comment.