forked from inversify/InversifyJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.test.ts
More file actions
63 lines (51 loc) · 1.47 KB
/
Copy pathexceptions.test.ts
File metadata and controls
63 lines (51 loc) · 1.47 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
import { expect } from "chai";
import * as ERROR_MSGS from "../../src/constants/error_msgs";
import { Container, inject, injectable } from "../../src/inversify";
describe("Node", () => {
it("Should throw if circular dependencies found", () => {
interface A {}
interface B {}
interface C {}
interface D {}
@injectable()
class A implements A {
public b: B;
public c: C;
public constructor(
@inject("B") b: B,
@inject("C") c: C
) {
this.b = b;
this.c = c;
}
}
@injectable()
class B implements B {}
@injectable()
class C implements C {
public d: D;
public constructor(@inject("D") d: D) {
this.d = d;
}
}
@injectable()
class D implements D {
public a: A;
public constructor(@inject("A") a: A) {
this.a = a;
}
}
const container = new Container();
container.bind<A>("A").to(A);
container.bind<B>("B").to(B);
container.bind<C>("C").to(C);
container.bind<D>("D").to(D);
function willThrow() {
const a = container.get<A>("A");
return a;
}
expect(willThrow).to.throw(
`${ERROR_MSGS.CIRCULAR_DEPENDENCY} A --> C --> D --> A`
);
});
});