From 167163e1b499f3c98799a2336204c5e27508c880 Mon Sep 17 00:00:00 2001 From: "Ioanna M. Dimitriou H" Date: Wed, 17 Jan 2024 00:08:06 +0100 Subject: [PATCH] Refactoring tests to use the Async Helpers. --- .../next/iterator-result-poisoned-wrapper.js | 17 +++++------ .../next/next-result-poisoned-wrapper.js | 17 +++++------ .../throw/throw-result-poisoned-wrapper.js | 30 ++++++++----------- 3 files changed, 27 insertions(+), 37 deletions(-) diff --git a/test/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-poisoned-wrapper.js b/test/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-poisoned-wrapper.js index 89224f2ecd0..7e424442b35 100644 --- a/test/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-poisoned-wrapper.js +++ b/test/built-ins/AsyncFromSyncIteratorPrototype/next/iterator-result-poisoned-wrapper.js @@ -36,10 +36,12 @@ info: | flags: [async] features: [async-iteration] +includes: [asyncHelpers.js] ---*/ var finallyCount = 0; -var thrownError = new Error("Catch me."); +function CatchError() {} +var thrownError = new CatchError(); function* gen() { try { @@ -59,12 +61,7 @@ async function* iter() { yield* gen(); } -iter().next().then( - function (result) { - throw new Test262Error("Resolving promise should throw."); - }, - function (err) { - assert.sameValue(err, thrownError, "Resolving promise should be rejected with thrown error"); - assert.sameValue(finallyCount, 1); - } -).then($DONE, $DONE); +asyncTest(async function () { + await assert.throwsAsync(CatchError, async () => iter().next(), "Promise should be rejected"); + assert.sameValue(finallyCount, 1, 'iterator closed properly'); +}) diff --git a/test/built-ins/AsyncFromSyncIteratorPrototype/next/next-result-poisoned-wrapper.js b/test/built-ins/AsyncFromSyncIteratorPrototype/next/next-result-poisoned-wrapper.js index 32f06c388f2..1016d00640b 100644 --- a/test/built-ins/AsyncFromSyncIteratorPrototype/next/next-result-poisoned-wrapper.js +++ b/test/built-ins/AsyncFromSyncIteratorPrototype/next/next-result-poisoned-wrapper.js @@ -36,10 +36,12 @@ info: | flags: [async] features: [async-iteration] +includes: [asyncHelpers.js] ---*/ var returnCount = 0; -var thrownError = new Error("Catch me."); +function CatchError() {} +var thrownError = new CatchError(); const obj = { [Symbol.iterator]() { @@ -64,12 +66,7 @@ async function* iter() { yield* obj; } -iter().next().then( - function (result) { - throw new Test262Error("Resolving promise should throw."); - }, - function (err) { - assert.sameValue(err, thrownError, "Resolving promise should be rejected with thrown error"); - assert.sameValue(returnCount, 1); - } -).then($DONE, $DONE); +asyncTest(async function () { + await assert.throwsAsync(CatchError, async () => iter().next(), "Promise should be rejected"); + assert.sameValue(returnCount, 1, 'iterator closed properly'); +}) diff --git a/test/built-ins/AsyncFromSyncIteratorPrototype/throw/throw-result-poisoned-wrapper.js b/test/built-ins/AsyncFromSyncIteratorPrototype/throw/throw-result-poisoned-wrapper.js index 71415ceaf87..d7ab9518c3b 100644 --- a/test/built-ins/AsyncFromSyncIteratorPrototype/throw/throw-result-poisoned-wrapper.js +++ b/test/built-ins/AsyncFromSyncIteratorPrototype/throw/throw-result-poisoned-wrapper.js @@ -41,10 +41,12 @@ info: | flags: [async] features: [async-iteration] +includes: [asyncHelpers.js] ---*/ var returnCount = 0; -var thrownError = new Error("Catch me."); +function CatchError() {} +var thrownError = new CatchError(); var uncaughtError = new Error("Don't catch me"); const obj = { @@ -76,19 +78,13 @@ async function* asyncg() { let iter = asyncg(); -iter.next().then(function () { - return iter.throw(uncaughtError).then( - function () { - throw new Test262Error("Resolving promise should throw."); - }, - function (err) { - assert.sameValue(err, thrownError, "Resolving promise should be rejected with thrown error"); - assert.sameValue(returnCount, 1); - - return iter.next().then(function (result) { - assert.sameValue(result.done, true, 'the iterator is completed'); - assert.sameValue(result.value, undefined, 'value is undefined'); - }) - } - ); -}).then($DONE, $DONE); +asyncTest(async function () { + await assert.throwsAsync(CatchError, async () => { + await iter.next(); + return iter.throw(uncaughtError); + }, "Promise should be rejected"); + assert.sameValue(returnCount, 1, 'iterator closed properly'); + const result = await iter.next(); + assert(result.done, "the iterator is completed"); + assert.sameValue(result.value, undefined, "value is undefined"); +})