asyncHelpers tests: Address code review feedback

This commit is contained in:
Cam Tenny 2023-02-10 12:25:20 -08:00 committed by Philip Chimento
parent e0d5b780e7
commit eb44f67274
18 changed files with 50 additions and 58 deletions

View File

@ -4,7 +4,7 @@
/*---
description: >
Functions that throw instances of the realm specified constructor function
satisfy the assertion, without cross realms collisions.
do not satisfy the assertion with cross realms collisions.
---*/
var intrinsicTypeError = TypeError;

View File

@ -6,11 +6,13 @@ description: |
includes: [asyncHelpers.js]
---*/
var called = false;
var msg = "Should not be rethrown";
function $DONE(error) {
called = true;
assert(error instanceof Test262Error);
assert.sameValue(error.message, msg, "Should report correct error");
}
asyncTest(function () {
throw new Test262Error("Should not be rethrown");
throw new Test262Error(msg);
});
assert(called, "asyncTest called $DONE with a synchronously thrown error");

View File

@ -8,6 +8,7 @@ includes: [asyncHelpers.js, compareArray.js]
const doneValues = [];
function $DONE(error) {
// Will be a TypeError from trying to invoke .then() on non-thenable
doneValues.push(error instanceof TypeError);
}
asyncTest(function () {

View File

@ -2,7 +2,7 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: |
The 'asyncTest' helper when called with async flag always returns to undefined.
The 'asyncTest' helper when called with async flag always returns undefined.
flags: [async]
includes: [asyncHelpers.js]
---*/

View File

@ -8,7 +8,8 @@ includes: [asyncHelpers.js]
function makePromise() {
return {
then(res, rej) {
throw new Test262Error("Should not be evaluated");
// Throw a different error than Test262Error to avoid confusion about what is rejecting
throw new Error("Should not be evaluated");
},
};
}

View File

@ -10,7 +10,7 @@ includes: [asyncHelpers.js]
var intrinsicTypeError = TypeError;
(async function () {
asyncTest(async function () {
function TypeError() {}
var caught = false;
@ -69,4 +69,4 @@ var intrinsicTypeError = TypeError;
"assert.throwsAsync did not reject a collision of constructor names"
);
}
})().then($DONE, $DONE);
})

View File

@ -10,10 +10,10 @@ includes: [asyncHelpers.js]
function MyError() {}
(async function () {
asyncTest(async function () {
const p = assert.throwsAsync(MyError, function () {
return Promise.reject(new MyError());
});
assert(p instanceof Promise);
await p;
})().then($DONE, $DONE);
});

View File

@ -2,14 +2,14 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: |
assert.throwsAsync returns a promise that rejects if funcOrThenable or the inner thenable synchronously throws.
assert.throwsAsync returns a promise that rejects if func or the inner thenable synchronously throws.
flags: [async]
includes: [asyncHelpers.js]
---*/
async function checkRejects(funcOrThenable) {
async function checkRejects(func) {
var caught = false;
const p = assert.throwsAsync(Test262Error, funcOrThenable);
const p = assert.throwsAsync(Test262Error, func);
assert(p instanceof Promise, "assert.throwsAsync should return a promise");
try {
await p;
@ -18,34 +18,23 @@ async function checkRejects(funcOrThenable) {
assert.sameValue(
e.constructor,
Test262Error,
"throwsAsync should reject improper funcOrThenable with a Test262Error"
"throwsAsync should reject improper function with a Test262Error"
);
} finally {
assert(
caught,
"assert.throwsAsync did not reject improper funcOrThenable " +
funcOrThenable
"assert.throwsAsync did not reject improper function " + func
);
}
}
(async function () {
asyncTest(async function () {
await checkRejects(function () {
throw new Error();
});
await checkRejects(function () {
throw new Test262Error();
});
await checkRejects({
then: function () {
throw new Error();
},
});
await checkRejects({
then: function () {
throw new Test262Error();
},
});
await checkRejects(function () {
return {
then: function () {
@ -60,4 +49,4 @@ async function checkRejects(funcOrThenable) {
},
};
});
})().then($DONE, $DONE);
});

View File

@ -8,7 +8,7 @@ flags: [async]
includes: [asyncHelpers.js]
---*/
(async function () {
asyncTest(async function () {
var caught = false;
const p = assert.throwsAsync(Error, function () {
@ -32,4 +32,4 @@ includes: [asyncHelpers.js]
"assert.throwsAsync did not reject when a value with incorrect constructor was thrown"
);
}
})().then($DONE, $DONE);
});

View File

@ -2,14 +2,14 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: |
assert.throwsAsync returns a promise that rejects if funcOrThenable is not a function returning a thenable or a thenable.
assert.throwsAsync calls $DONE with a rejecting value if func is not a function returning a thenable.
flags: [async]
includes: [asyncHelpers.js]
---*/
async function checkRejects(funcOrThenable) {
async function checkRejects(func) {
var caught = false;
const p = assert.throwsAsync(Test262Error, funcOrThenable);
const p = assert.throwsAsync(Test262Error, func);
assert(p instanceof Promise, "assert.throwsAsync should return a promise");
try {
await p;
@ -18,28 +18,27 @@ async function checkRejects(funcOrThenable) {
assert.sameValue(
e.constructor,
Test262Error,
"throwsAsync should reject improper funcOrThenable with a Test262Error"
"throwsAsync should reject improper function with a Test262Error"
);
} finally {
assert(
caught,
"assert.throwsAsync did not reject improper funcOrThenable " +
funcOrThenable
"assert.throwsAsync did not reject improper function " + func
);
}
}
(async function () {
asyncTest(async function () {
await checkRejects(null);
await checkRejects({});
await checkRejects("string");
await checkRejects(10);
await checkRejects();
await checkRejects({ then: null });
await checkRejects({ then: {} });
await checkRejects({ then: "string" });
await checkRejects({ then: 10 });
await checkRejects({ then: undefined });
await checkRejects({
then: function (res, rej) {
res(true);
},
});
await checkRejects(function () {
return null;
});
@ -68,4 +67,4 @@ async function checkRejects(funcOrThenable) {
await checkRejects(function () {
return { then: undefined };
});
})().then($DONE, $DONE);
});

View File

@ -8,7 +8,7 @@ flags: [async]
includes: [asyncHelpers.js]
---*/
(async function () {
asyncTest(async function () {
var p = assert.throwsAsync(Error, async function () {
throw new Error();
});
@ -44,4 +44,4 @@ includes: [asyncHelpers.js]
});
assert(p instanceof Promise);
await p;
})().then($DONE, $DONE);
});

View File

@ -7,7 +7,7 @@ flags: [async]
includes: [asyncHelpers.js]
---*/
(async function () {
asyncTest(async function () {
var caught = false;
const p = assert.throwsAsync();
@ -29,4 +29,4 @@ includes: [asyncHelpers.js]
"assert.throwsAsync did not reject when invoked without arguments"
);
}
})().then($DONE, $DONE);
});

View File

@ -7,7 +7,7 @@ flags: [async]
includes: [asyncHelpers.js]
---*/
(async function () {
asyncTest(async function () {
var caught = false;
const p = assert.throwsAsync(Error, async function () {});
@ -29,4 +29,4 @@ includes: [asyncHelpers.js]
"assert.throwsAsync did not reject when the thenable did not reject"
);
}
})().then($DONE, $DONE);
});

View File

@ -7,7 +7,7 @@ flags: [async]
includes: [asyncHelpers.js]
---*/
(async function () {
asyncTest(async function () {
var caught = false;
const p = assert.throwsAsync(Error, async function () {
@ -31,4 +31,4 @@ includes: [asyncHelpers.js]
"assert.throwsAsync did not reject when null was thrown"
);
}
})().then($DONE, $DONE);
});

View File

@ -7,7 +7,7 @@ flags: [async]
includes: [asyncHelpers.js]
---*/
(async function () {
asyncTest(async function () {
var caught = false;
const p = assert.throwsAsync(Error, async function () {
@ -31,4 +31,4 @@ includes: [asyncHelpers.js]
"assert.throwsAsync did not reject when a primitive was thrown"
);
}
})().then($DONE, $DONE);
});

View File

@ -7,7 +7,7 @@ flags: [async]
includes: [asyncHelpers.js]
---*/
(async function () {
asyncTest(async function () {
var caught = false;
const p = assert.throwsAsync(
@ -32,4 +32,4 @@ includes: [asyncHelpers.js]
"assert.throwsAsync did not reject when the thenable resolved with an error"
);
}
})().then($DONE, $DONE);
});

View File

@ -3,12 +3,12 @@
/*---
description: |
Thenables that reject with instances of the realm specified constructor function
satisfy the assertion, without cross realms collisions.
do not satisfy the assertion with cross realms collisions.
flags: [async]
includes: [asyncHelpers.js]
---*/
(async function () {
asyncTest(async function () {
var intrinsicTypeError = TypeError;
var caught = false;
var realmGlobal = $262.createRealm().global;
@ -34,4 +34,4 @@ includes: [asyncHelpers.js]
"assert.throwsAsync did not reject when a different realm's error was thrown"
);
}
})().then($DONE, $DONE);
});

View File

@ -7,7 +7,7 @@ flags: [async]
includes: [asyncHelpers.js]
---*/
(async function () {
asyncTest(async function () {
var caught = false;
const p = assert.throwsAsync(function () {});
assert(p instanceof Promise);
@ -28,4 +28,4 @@ includes: [asyncHelpers.js]
"assert.throwsAsync did not reject when invoked with a single argumemnt"
);
}
})().then($DONE, $DONE);
});