Tests/LibJS: Split await Promise constructor observability test into two

This makes it easier to figure out the expected behaviour of each
of the tests since it was difficult to determine what each case
was aiming to test.
This commit is contained in:
Shannon Booth 2025-04-06 23:27:10 +12:00
commit cba9c099c8

View file

@ -257,7 +257,7 @@ describe("await thenables", () => {
}); });
}); });
describe("await observably looks up constructor of Promise objects", () => { describe("await observably looks up constructor of Promise objects increasing call count", () => {
let calls = 0; let calls = 0;
function makeConstructorObservable(promise) { function makeConstructorObservable(promise) {
Object.defineProperty(promise, "constructor", { Object.defineProperty(promise, "constructor", {
@ -276,9 +276,6 @@ describe("await observably looks up constructor of Promise objects", () => {
resolve(); resolve();
}) })
); );
await makeConstructorObservable(new Boolean(true));
await makeConstructorObservable({});
await makeConstructorObservable(new Number(2));
try { try {
await makeConstructorObservable(Promise.reject(3)); await makeConstructorObservable(Promise.reject(3));
} catch {} } catch {}
@ -292,3 +289,25 @@ describe("await observably looks up constructor of Promise objects", () => {
runQueuedPromiseJobs(); runQueuedPromiseJobs();
expect(calls).toBe(4); expect(calls).toBe(4);
}); });
describe("await observably looks up constructor of Promise objects not increasing call count", () => {
let calls = 0;
function makeConstructorObservable(promise) {
Object.defineProperty(promise, "constructor", {
get() {
calls++;
return Promise;
},
});
return promise;
}
async function test() {
await makeConstructorObservable(new Boolean(true));
await makeConstructorObservable({});
await makeConstructorObservable(new Number(2));
}
test();
runQueuedPromiseJobs();
expect(calls).toBe(0);
});