feat(ElementInjector): throw when encounter a cyclic dependency

This commit is contained in:
vsavkin
2014-10-27 13:02:46 -04:00
parent b0c9d05ea7
commit 9bd65abb32
5 changed files with 70 additions and 31 deletions
@@ -40,6 +40,14 @@ class NeedsService {
}
}
class A_Needs_B {
constructor(dep){}
}
class B_Needs_A {
constructor(dep){}
}
class NeedsView {
@FIELD("view:Object")
constructor(@Inject(View) view) {
@@ -215,6 +223,16 @@ export function main() {
expect(inj.get(View)).toEqual(view);
});
it("should handle cyclic dependencies", function () {
expect(() => {
injector([
bind(A_Needs_B).toFactory((a) => new A_Needs_B(a), [B_Needs_A]),
bind(B_Needs_A).toFactory((a) => new B_Needs_A(a), [A_Needs_B])
]);
}).toThrowError('Cannot instantiate cyclic dependency! ' +
'(A_Needs_B -> B_Needs_A -> A_Needs_B)');
});
});
});
}