Increase precision of assertions for Error Cause

Minimize the code provided to the `assert.throws` utility in order to
reduce the possibility of false positives and to improve failure
messages in non-conforming runtimes.
This commit is contained in:
Mike Pennisi 2021-04-23 14:55:09 -04:00 committed by Rick Waldron
parent 9b622bf093
commit fd029d2d52
1 changed files with 17 additions and 15 deletions

View File

@ -22,29 +22,31 @@ features: [error-cause]
---*/ ---*/
var message = "my-message"; var message = "my-message";
var options;
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// CHECK#0 // CHECK#0
assert.throws(Test262Error, function () { options = new Proxy({}, {
var options = new Proxy({}, {
has(target, prop) { has(target, prop) {
if (prop === "cause") { if (prop === "cause") {
throw new Test262Error("HasProperty"); throw new Test262Error("HasProperty");
} }
return prop in target; return prop in target;
}, },
}); });
var error = new Error(message, options); assert.throws(Test262Error, function () {
new Error(message, options);
}, "HasProperty"); }, "HasProperty");
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// CHECK#1 // CHECK#1
assert.throws(Test262Error, function () { options = {
var options = {
get cause() { get cause() {
throw new Test262Error("Get Cause"); throw new Test262Error("Get Cause");
}, },
}; };
var error = new Error(message, options); assert.throws(Test262Error, function () {
new Error(message, options);
}, "Get Cause"); }, "Get Cause");
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////