/
test-examples.spec.ts
54 lines (37 loc) · 1.14 KB
/
test-examples.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { create, use } from "../index";
let shape = create.shape();
beforeEach(() => (shape = create.shape()));
test("check value of store", () => {
const $count = create.store<number>(0);
const counter = create.component(() => {
const setCount = use.dispatch($count);
setCount(7);
return null;
});
shape.attach(counter());
expect(shape.getValue($count)).toBe(7);
});
test("check state of event", () => {
const changeCount = create.event<number>();
const counter = create.component(() => {
const change = use.dispatch(changeCount);
change(2);
return null;
});
shape.attach(counter());
expect(shape.getEventState(changeCount)).toEqual({ payload: 2 });
});
test("async check value of store", async () => {
const request = () => {
return new Promise<number>((resolve) => setTimeout(() => resolve(3), 200));
};
const $count = create.store<number>(0);
const counter = create.component(() => {
const setCount = use.dispatch($count);
use.promise(request()).then(setCount);
return null;
});
shape.attach(counter());
await shape.wait();
expect(shape.getValue($count)).toBe(3);
});