-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcircular.spec.ts
More file actions
61 lines (56 loc) · 1.29 KB
/
circular.spec.ts
File metadata and controls
61 lines (56 loc) · 1.29 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
import { describe, expect, test } from "vitest";
import { manage } from "../src/index.js";
describe("circular", () => {
test("direct", () => {
class A {
public b = 1;
public parent: A | null = null;
}
const a = new A();
const ma = manage(a);
ma.parent = ma;
});
test("indirect", () => {
class A {
public b = 1;
public parent: A | null = null;
}
const a = new A();
const b = new A();
const ma = manage(a);
const mb = manage(b);
ma.parent = mb;
mb.parent = ma;
});
test("3-steps away", () => {
class A {
public b = 1;
public parent: A | null = null;
}
const a = new A();
const b = new A();
const c = new A();
const ma = manage(a);
const mb = manage(b);
const mc = manage(c);
ma.parent = mb;
mb.parent = mc;
mc.parent = ma;
});
test("manage after circular", () => {
class A {
constructor(public b?: B) {}
}
class B {
constructor(public a: A) {}
}
const a = new A();
const b = new B(a);
a.b = b;
const ma = manage(a); // will not trigger "RangeError: Maximum call stack size exceeded"
expect(ma).toBeDefined();
expect(ma.b).toBeDefined();
expect(ma.b?.a).toBeDefined();
expect(ma.b?.a.b).toBeDefined();
});
});