Merge pull request #330 from bocoup/correct-promise-test

Fix bugs in Promise tests
This commit is contained in:
Brian Terlson 2015-06-23 17:14:28 -07:00
commit 134c484abb
3 changed files with 28 additions and 41 deletions

View File

@ -11,20 +11,17 @@ description: iterator.next throws, causing Promise.all to reject
---*/ ---*/
var iterThrows = {}; var iterThrows = {};
Object.defineProperty(iterThrows, Symbol.iterator, { var error = new Test262Error();
get: function () { iterThrows[Symbol.iterator] = function() {
return { return {
next: function () { next: function () {
throw new Error("abrupt completion"); throw error;
} }
}; };
} };
});
Promise.all(iterThrows).then(function () { Promise.all(iterThrows).then(function () {
$ERROR('Promise unexpectedly resolved: Promise.all(iterThrows) should throw TypeError'); $ERROR('Promise unexpectedly resolved: Promise.all(iterThrows) should throw TypeError');
},function (err) { },function (reason) {
if (!(err instanceof TypeError)) { assert.sameValue(reason, error);
$ERROR('Expected TypeError, got ' + err);
}
}).then($DONE,$DONE); }).then($DONE,$DONE);

View File

@ -14,21 +14,14 @@ var p = Promise.resolve("foo");
Object.defineProperty(p, "constructor", { Object.defineProperty(p, "constructor", {
get: function () { get: function () {
throw new Error("abrupt completion"); throw new Test262Error();
} }
}); });
try { assert.throws(Test262Error, function() {
p.then(function() { p.then(function() {
$ERROR("Should never be called."); $ERROR("Should never be called.");
}, function() { }, function() {
$ERROR("Should never be called."); $ERROR("Should never be called.");
}); });
} catch (e) { });
if (!(e instanceof Error)) {
$ERROR("Expected Error, got " + e);
}
if (e.message !== "abrupt completion") {
$ERROR("Expected the Error we threw, got " + e);
}
}

View File

@ -8,21 +8,18 @@ description: Promise.race rejects if IteratorStep throws
---*/ ---*/
var iterThrows = {}; var iterThrows = {};
Object.defineProperty(iterThrows, Symbol.iterator, { var error = new Test262Error();
get: function () { iterThrows[Symbol.iterator] = function () {
return { return {
next: function () { next: function () {
throw new Error("abrupt completion"); throw error;
} }
}; };
} };
});
Promise.race(iterThrows).then(function () { Promise.race(iterThrows).then(function () {
$ERROR('Promise unexpectedly fulfilled: Promise.race(iterThrows) should throw TypeError'); $ERROR('Promise unexpectedly fulfilled: Promise.race(iterThrows) should throw TypeError');
},function (err) { }, function (reason) {
if (!(err instanceof TypeError)) { assert.sameValue(reason, error);
$ERROR('Expected TypeError, got ' + err);
}
}).then($DONE,$DONE); }).then($DONE,$DONE);