-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaction.spec.ts
More file actions
50 lines (44 loc) · 1007 Bytes
/
action.spec.ts
File metadata and controls
50 lines (44 loc) · 1007 Bytes
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
import { describe, expect, test } from "vitest";
import { action, autoRun, manage } from "../src/index.js";
describe("action", () => {
test("default", () => {
const arr = manage([1, 2, 3, 4, 5]);
let count = 0;
const runner = autoRun(() => {
count++;
return JSON.stringify(arr);
});
runner.start(); // trigger the first run
function f() {
arr.push(6);
arr.push(7);
arr.push(8);
}
const f2 = action(f);
f2();
runner.stop();
expect(count).toBe(2);
});
test("decorator", () => {
const arr = manage([1, 2, 3, 4, 5]);
class A {
public temp = 1;
@action
f() {
expect(this.temp).toBe(1);
arr.push(6);
arr.push(7);
arr.push(8);
}
}
let count = 0;
const runner = autoRun(() => {
count++;
return JSON.stringify(arr);
});
runner.start(); // trigger the first run
new A().f();
runner.stop();
expect(count).toBe(2);
});
});