repos / starfx

a micro-mvc framework for react apps
git clone https://github.com/neurosnap/starfx.git

starfx / src / test
Eric Bower  ·  2025-06-06

safe.test.ts

 1import { call, run } from "../index.js";
 2import { expect, test } from "../test.js";
 3
 4test("should call the generator function", async () => {
 5  expect.assertions(1);
 6  function* me() {
 7    return "valid";
 8  }
 9
10  await run(function* () {
11    const result = yield* call(me);
12    expect(result).toBe("valid");
13  });
14});
15
16test("should return an Err()", async () => {
17  expect.assertions(1);
18  const err = new Error("bang!");
19  function* me() {
20    throw err;
21  }
22
23  await run(function* () {
24    try {
25      yield* call(me);
26    } catch (err) {
27      expect(err).toEqual(err);
28    }
29  });
30});
31
32test("should call a promise", async () => {
33  expect.assertions(1);
34  const me = () =>
35    new Promise<string>((resolve) => {
36      setTimeout(() => {
37        resolve("valid");
38      }, 10);
39    });
40
41  await run(function* () {
42    const result = yield* call(me);
43    expect(result).toEqual("valid");
44  });
45});