Skip to content

Commit

Permalink
Added test for asynchronous middleware.
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoguchi committed Feb 23, 2011
1 parent 9345076 commit 2b95cb6
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,5 +346,42 @@ module.exports = {
});
var a = new A();
a.set('hello', 'world');
},

'should not invoke the target method until all asynchronous middleware have invoked dones': function () {
var counter = 0;
var A = function () {};
_.extend(A, hooks);
A.hook('set', function (path, val) {
counter++;
this[path] = val;
counter.should.equal(7);
});
A.pre('set', function (next, path, val) {
counter++;
next();
});
A.pre('set', function (next, done, path, val) {
counter++;
setTimeout(function () {
counter++;
done();
}, 1000);
next();
}, true);
A.pre('set', function (next, path, val) {
counter++;
next();
});
A.pre('set', function (next, done, path, val) {
counter++;
setTimeout(function () {
counter++;
done();
}, 500);
next();
}, true);
var a = new A();
a.set('hello', 'world');
}
};

0 comments on commit 2b95cb6

Please sign in to comment.