Skip to content

Commit

Permalink
Added test case to make sure that callback isn't called multiple time…
Browse files Browse the repository at this point in the history
…s in asyncify
  • Loading branch information
raydog committed Jun 23, 2016
1 parent 066c3f1 commit 3ef90da
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions mocha_test/asyncify.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ describe('asyncify', function(){
'rsvp'
];

// Both Bluebird and native promises emit these events. We handle it because Bluebird
// will report these rejections to stderr if we don't, which is a great feature for
// normal cases, but not here, since we expect unhandled rejections:
process.on('unhandledRejection', function () {
// Ignore.
});

names.forEach(function(name) {
describe(name, function() {

Expand Down Expand Up @@ -111,6 +118,25 @@ describe('asyncify', function(){
done();
});
});

it('callback error', function(done) {
var promisified = function(argument) {
return new Promise(function (resolve) {
resolve(argument + " resolved");
});
};
var call_count = 0;
async.asyncify(promisified)("argument", function () {
call_count++;
if (call_count === 1) {
throw new Error("error in callback");
}
});
setTimeout(function () {
expect(call_count).to.equal(1);
done();
}, 15);
});
});
});
});
Expand Down

0 comments on commit 3ef90da

Please sign in to comment.