-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.ts
More file actions
88 lines (73 loc) · 1.9 KB
/
test.ts
File metadata and controls
88 lines (73 loc) · 1.9 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { createEffect, createEvent, createStore } from "effector";
import { test } from "uvu";
import { equal, throws } from "uvu/assert";
import {
ev$all,
ev$flatAll,
ev$last,
fx$all,
fx$flatAll,
fx$last,
} from "./index.js";
test("fx$last - success", () => {
const fx = fx$last(createEffect<number, number>((x) => x));
fx(0);
fx(1);
equal(fx.$last.getState() + 1, 2);
});
test("fx$last - error", () => {
throws(() => fx$last(createStore(0) as any));
});
test("ev$last - success", () => {
const ev = ev$last(createEvent<number>());
ev(0);
ev(1);
equal(ev.$last.getState() + 1, 2);
});
test("ev$last - error", () => {
throws(() => ev$last(createStore(0) as any));
});
test("fx$all - success", () => {
const fx = fx$all(createEffect<number, number>((x) => x));
fx(0);
fx(1);
equal(fx.$all.getState().concat(2), [0, 1, 2]);
});
test("fx$all - error", () => {
throws(() => fx$all(createStore(0) as any));
});
test("ev$all - success", () => {
const ev = ev$all(createEvent<number>());
ev(0);
ev(1);
equal(ev.$all.getState().concat(2), [0, 1, 2]);
});
test("ev$all - error", () => {
throws(() => ev$all(createStore(0) as any));
});
test("fx$flatAll - success", () => {
const fx = fx$flatAll(createEffect<number, number[]>((x) => [x]));
fx(0);
fx(1);
equal(fx.$flatAll.getState().concat(2), [0, 1, 2]);
});
test("fx$flatAll - error", () => {
throws(() => fx$flatAll(createStore(0) as any));
});
test("ev$flatAll - success", () => {
const ev = ev$flatAll(createEvent<number[]>());
ev([0]);
ev([1]);
equal(ev.$flatAll.getState().concat(2), [0, 1, 2]);
});
test("ev$flatAll - error", () => {
throws(() => ev$flatAll(createStore(0) as any));
});
test("composition", () => {
const fx = fx$all(fx$last(createEffect<number, number>((x) => x)));
fx(0);
fx(1);
equal(fx.$last.getState() + 1, 2);
equal(fx.$all.getState().concat(2), [0, 1, 2]);
});
test.run();