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 = {};
Object.defineProperty(iterThrows, Symbol.iterator, {
get: function () {
return {
next: function () {
throw new Error("abrupt completion");
}
};
}
});
var error = new Test262Error();
iterThrows[Symbol.iterator] = function() {
return {
next: function () {
throw error;
}
};
};
Promise.all(iterThrows).then(function () {
$ERROR('Promise unexpectedly resolved: Promise.all(iterThrows) should throw TypeError');
},function (err) {
if (!(err instanceof TypeError)) {
$ERROR('Expected TypeError, got ' + err);
}
},function (reason) {
assert.sameValue(reason, error);
}).then($DONE,$DONE);

View File

@ -14,21 +14,14 @@ var p = Promise.resolve("foo");
Object.defineProperty(p, "constructor", {
get: function () {
throw new Error("abrupt completion");
throw new Test262Error();
}
});
try {
p.then(function () {
$ERROR("Should never be called.");
}, function () {
$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);
}
}
assert.throws(Test262Error, function() {
p.then(function() {
$ERROR("Should never be called.");
}, function() {
$ERROR("Should never be called.");
});
});

View File

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