mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 05:55:36 +02:00
parent
57c7d06bf1
commit
5217ef396e
@ -28,84 +28,86 @@ function asyncTest(testFunc) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.throwsAsync = async function (expectedErrorConstructor, func, message) {
|
assert.throwsAsync = function (expectedErrorConstructor, func, message) {
|
||||||
var innerThenable;
|
return new Promise(function (resolve) {
|
||||||
if (message === undefined) {
|
var innerThenable;
|
||||||
message = "";
|
if (message === undefined) {
|
||||||
} else {
|
message = "";
|
||||||
message += " ";
|
} else {
|
||||||
}
|
message += " ";
|
||||||
if (typeof func === "function") {
|
|
||||||
try {
|
|
||||||
innerThenable = func();
|
|
||||||
if (
|
|
||||||
innerThenable === null ||
|
|
||||||
typeof innerThenable !== "object" ||
|
|
||||||
typeof innerThenable.then !== "function"
|
|
||||||
) {
|
|
||||||
message +=
|
|
||||||
"Expected to obtain an inner promise that would reject with a" +
|
|
||||||
expectedErrorConstructor.name +
|
|
||||||
" but result was not a thenable";
|
|
||||||
throw new Test262Error(message);
|
|
||||||
}
|
|
||||||
} catch (thrown) {
|
|
||||||
message +=
|
|
||||||
"Expected a " +
|
|
||||||
expectedErrorConstructor.name +
|
|
||||||
" to be thrown asynchronously but an exception was thrown synchronously while obtaining the inner promise";
|
|
||||||
throw new Test262Error(message);
|
|
||||||
}
|
}
|
||||||
} else {
|
if (typeof func === "function") {
|
||||||
message +=
|
try {
|
||||||
"assert.throwsAsync called with an argument that is not a function";
|
innerThenable = func();
|
||||||
throw new Test262Error(message);
|
if (
|
||||||
}
|
innerThenable === null ||
|
||||||
|
typeof innerThenable !== "object" ||
|
||||||
try {
|
typeof innerThenable.then !== "function"
|
||||||
return innerThenable.then(
|
) {
|
||||||
function () {
|
message +=
|
||||||
|
"Expected to obtain an inner promise that would reject with a" +
|
||||||
|
expectedErrorConstructor.name +
|
||||||
|
" but result was not a thenable";
|
||||||
|
throw new Test262Error(message);
|
||||||
|
}
|
||||||
|
} catch (thrown) {
|
||||||
message +=
|
message +=
|
||||||
"Expected a " +
|
"Expected a " +
|
||||||
expectedErrorConstructor.name +
|
expectedErrorConstructor.name +
|
||||||
" to be thrown asynchronously but no exception was thrown at all";
|
" to be thrown asynchronously but an exception was thrown synchronously while obtaining the inner promise";
|
||||||
throw new Test262Error(message);
|
throw new Test262Error(message);
|
||||||
},
|
|
||||||
function (thrown) {
|
|
||||||
var expectedName, actualName;
|
|
||||||
if (typeof thrown !== "object" || thrown === null) {
|
|
||||||
message += "Thrown value was not an object!";
|
|
||||||
throw new Test262Error(message);
|
|
||||||
} else if (thrown.constructor !== expectedErrorConstructor) {
|
|
||||||
expectedName = expectedErrorConstructor.name;
|
|
||||||
actualName = thrown.constructor.name;
|
|
||||||
if (expectedName === actualName) {
|
|
||||||
message +=
|
|
||||||
"Expected a " +
|
|
||||||
expectedName +
|
|
||||||
" but got a different error constructor with the same name";
|
|
||||||
} else {
|
|
||||||
message +=
|
|
||||||
"Expected a " + expectedName + " but got a " + actualName;
|
|
||||||
}
|
|
||||||
throw new Test262Error(message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
} catch (thrown) {
|
|
||||||
if (typeof thrown !== "object" || thrown === null) {
|
|
||||||
message +=
|
|
||||||
"Expected a " +
|
|
||||||
expectedErrorConstructor.name +
|
|
||||||
" to be thrown asynchronously but innerThenable synchronously threw a value that was not an object ";
|
|
||||||
} else {
|
} else {
|
||||||
message +=
|
message +=
|
||||||
"Expected a " +
|
"assert.throwsAsync called with an argument that is not a function";
|
||||||
expectedErrorConstructor.name +
|
throw new Test262Error(message);
|
||||||
" to be thrown asynchronously but a " +
|
|
||||||
thrown.constructor.name +
|
|
||||||
" was thrown synchronously";
|
|
||||||
}
|
}
|
||||||
throw new Test262Error(message);
|
|
||||||
}
|
try {
|
||||||
|
resolve(innerThenable.then(
|
||||||
|
function () {
|
||||||
|
message +=
|
||||||
|
"Expected a " +
|
||||||
|
expectedErrorConstructor.name +
|
||||||
|
" to be thrown asynchronously but no exception was thrown at all";
|
||||||
|
throw new Test262Error(message);
|
||||||
|
},
|
||||||
|
function (thrown) {
|
||||||
|
var expectedName, actualName;
|
||||||
|
if (typeof thrown !== "object" || thrown === null) {
|
||||||
|
message += "Thrown value was not an object!";
|
||||||
|
throw new Test262Error(message);
|
||||||
|
} else if (thrown.constructor !== expectedErrorConstructor) {
|
||||||
|
expectedName = expectedErrorConstructor.name;
|
||||||
|
actualName = thrown.constructor.name;
|
||||||
|
if (expectedName === actualName) {
|
||||||
|
message +=
|
||||||
|
"Expected a " +
|
||||||
|
expectedName +
|
||||||
|
" but got a different error constructor with the same name";
|
||||||
|
} else {
|
||||||
|
message +=
|
||||||
|
"Expected a " + expectedName + " but got a " + actualName;
|
||||||
|
}
|
||||||
|
throw new Test262Error(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
} catch (thrown) {
|
||||||
|
if (typeof thrown !== "object" || thrown === null) {
|
||||||
|
message +=
|
||||||
|
"Expected a " +
|
||||||
|
expectedErrorConstructor.name +
|
||||||
|
" to be thrown asynchronously but innerThenable synchronously threw a value that was not an object ";
|
||||||
|
} else {
|
||||||
|
message +=
|
||||||
|
"Expected a " +
|
||||||
|
expectedErrorConstructor.name +
|
||||||
|
" to be thrown asynchronously but a " +
|
||||||
|
thrown.constructor.name +
|
||||||
|
" was thrown synchronously";
|
||||||
|
}
|
||||||
|
throw new Test262Error(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
@ -9,8 +9,8 @@ flags: [async]
|
|||||||
includes: [asyncHelpers.js]
|
includes: [asyncHelpers.js]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
asyncTest(async function() {
|
asyncTest(function () {
|
||||||
await assert.throwsAsync(
|
return assert.throwsAsync(
|
||||||
Test262Error,
|
Test262Error,
|
||||||
function () {
|
function () {
|
||||||
Promise.try(function () { throw new Test262Error(); })
|
Promise.try(function () { throw new Test262Error(); })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user