-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.spec.ts
51 lines (45 loc) · 1.03 KB
/
action.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
import { describe, expect, test } from 'vitest';
import { action, manage, autoRun } from '../src';
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;
// eslint-disable-next-line prettier/prettier
@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);
});
});