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