Skip to content

Commit

Permalink
Add another test
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Nov 4, 2019
1 parent 952d200 commit 4b4a14c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
@@ -0,0 +1,34 @@
const log = [];

async function* inner() {
try {
log.push(1);
yield "a";
log.push(2);
yield "b";
log.push(3);
} finally {
log.push(4);
yield "c";
log.push(5);
}
}

async function* outer() {
log.push(6);
yield* inner();
log.push(7);
}

return (async () => {
const iterator = outer();

let res = await iterator.next();
expect(res).toEqual({ value: "a", done: false });
expect(log).toEqual([6, 1]);

const [res1, res2] = await Promise.all([ iterator.return("x"), iterator.return("y") ]);
expect(res1).toEqual({ value: "c", done: false });
expect(res2).toEqual({ value: "y", done: true });
expect(log).toEqual([6, 1, 4]);
})();
Expand Up @@ -27,11 +27,11 @@ return (async () => {
expect(res).toEqual({ value: "a", done: false });
expect(log).toEqual([6, 1]);

res = await iterator.return();
res = await iterator.return("x");
expect(res).toEqual({ value: "c", done: false });
expect(log).toEqual([6, 1, 4]);

res = await iterator.return();
expect(res).toEqual({ value: undefined, done: true });
res = await iterator.return("y");
expect(res).toEqual({ value: "y", done: true });
expect(log).toEqual([6, 1, 4]);
})();
@@ -0,0 +1,3 @@
{
"minNodeVersion": "8.0.0"
}

0 comments on commit 4b4a14c

Please sign in to comment.