Skip to content

Commit

Permalink
Refactoring tests to use the Async Helpers.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioannad committed Jan 16, 2024
1 parent 31c85bf commit 167163e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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');
})
Original file line number Diff line number Diff line change
Expand Up @@ -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]() {
Expand All @@ -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');
})
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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");
})

0 comments on commit 167163e

Please sign in to comment.