Skip to content

Commit

Permalink
Add tests for assimilating thenables.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb authored and cscott committed Jun 4, 2015
1 parent a67dbe8 commit 3a5eff3
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/promise/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,48 @@ describe('Promise', function () {
Promise.all.call(StealingPromiseConstructor, iterable);
});
});

specify('resolve with a thenable calls it once', function () {
var resolve;
var p = new Promise(function (r) { resolve = r; });
var count = 0;
resolve({
then: function () {
++count;
throw new RangeError('reject the promise');
}
});
var a = p.then(function () {})['catch'](function (err) {
assert.equal(count, 1);
assert.ok(err instanceof RangeError);
});
var b = p.then(function () {})['catch'](function (err) {
assert.equal(count, 1);
assert.ok(err instanceof RangeError);
});
return Promise.all([a, b]);
});

specify('resolve with a thenable that throws on .then, throws immediately', function () {
var resolve;
var p = new Promise(function (r) { resolve = r; });
var count = 0;
var thenable = Object.defineProperty({}, 'then', {
get: function () {
++count;
throw new RangeError('no then for you');
}
});
resolve(thenable);
assert.equal(count, 1);
var a = p.then(function () {})['catch'](function (err) {
assert.equal(count, 1);
assert.ok(err instanceof RangeError);
});
var b = p.then(function () {})['catch'](function (err) {
assert.equal(count, 1);
assert.ok(err instanceof RangeError);
});
return Promise.all([a, b]);
});
});

0 comments on commit 3a5eff3

Please sign in to comment.