typed-utilities
Version:
Strongly typed general purpose utilities
68 lines (61 loc) • 1.5 kB
JavaScript
;
var _ = require("..");
describe(`Iterator`, () => {
test(`next`, () => {
function* gen() {
yield 1;
yield 2;
yield 3;
}
const iter = gen();
expect((0, _.next)(iter)).toEqual(1);
expect((0, _.next)(iter)).toEqual(2);
expect((0, _.next)(iter)).toEqual(3);
expect(() => (0, _.next)(iter)).toThrow();
});
test(`nextify`, () => {
function* gen() {
yield 1;
yield 2;
yield 3;
}
const iter = gen();
const next = (0, _.nextify)(iter);
expect(next()).toEqual(1);
expect(next()).toEqual(2);
expect(next()).toEqual(3);
expect(next).toThrow();
});
test(`runToCompletion`, async () => {
function* gen1() {
yield 1;
yield 2;
yield 3;
return 4;
}
const gen1Result = await (0, _.runToCompletion)(gen1());
expect(gen1Result).toEqual(4);
function* gen2() {
yield 1;
yield 2;
throw new Error();
}
await expect(async () => await (0, _.runToCompletion)(gen2())).rejects.toBeTruthy();
});
test(`withRunToCompletion`, async () => {
const fn = (0, _.withRunToCompletion)(function* () {
yield 1;
yield 2;
yield 3;
return 4;
});
const result = await fn();
expect(result).toEqual(4);
});
test(`unnested withRunToCompletion`, (0, _.withRunToCompletion)(function* () {
yield 3;
yield 4;
yield expect(5).toEqual(5);
}));
});
//# sourceMappingURL=Iterator.test.js.map