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

create-store.test.ts

 1import { call } from "../index.js";
 2import { createStore, select } from "../store/index.js";
 3import { expect, test } from "../test.js";
 4
 5interface TestState {
 6  user: { id: string };
 7}
 8
 9test("should be able to grab values from store", async () => {
10  let actual;
11  const store = createStore({ initialState: { user: { id: "1" } } });
12  await store.run(function* () {
13    actual = yield* select((s: TestState) => s.user);
14  });
15  expect(actual).toEqual({ id: "1" });
16});
17
18test("should be able to grab store from a nested call", async () => {
19  let actual;
20  const store = createStore({ initialState: { user: { id: "2" } } });
21  await store.run(function* () {
22    actual = yield* call(function* () {
23      return yield* select((s: TestState) => s.user);
24    });
25  });
26  expect(actual).toEqual({ id: "2" });
27});