Permalink
Browse files

Merge pull request #3 from aheckmann/nextTwice

fixed calling next() 2x after throwing
  • Loading branch information...
2 parents 1e9d8ec + d2027b7 commit 4ba9c0f77cafc9bd48899abc598d6853f5cf0adc @bnoguchi committed Feb 25, 2012
Showing with 11 additions and 7 deletions.
  1. +1 −1 hooks.js
  2. +10 −6 test.js
View
2 hooks.js
@@ -155,7 +155,7 @@ module.exports = {
function once (fn, scope) {
return function fnWrapper () {
if (fnWrapper.hookCalled) return;
- fn.apply(scope, arguments);
fnWrapper.hookCalled = true;
+ fn.apply(scope, arguments);
};
}
View
16 test.js
@@ -525,7 +525,7 @@ module.exports = {
}, 1000);
},
- 'calling the same next multiple times should have the effect of only calling it once': function () {
+ 'calling the same next multiple times should have the effect of only calling it once': function (beforeExit) {
var A = function () {
this.acked = false;
};
@@ -535,17 +535,21 @@ module.exports = {
this.acked = true;
});
A.pre('ack', function (next) {
- next();
- next();
+ // force a throw to re-exec next()
+ try {
+ next(new Error('bam'));
+ } catch (err) {
+ next();
+ }
});
A.pre('ack', function (next) {
- // Notice that next() is not invoked here
+ next();
});
var a = new A();
a.ack();
- setTimeout( function () {
+ beforeExit( function () {
a.acked.should.be.false;
- }, 1000);
+ });
},
'asynchronous middleware should be able to pass an error via `done`, stopping the middleware chain': function () {

0 comments on commit 4ba9c0f

Please sign in to comment.