feat(di): add support for optional dependencies
This commit is contained in:
+17
-1
@@ -1,5 +1,5 @@
|
||||
import {describe, ddescribe, it, iit, expect, beforeEach} from 'angular2/test_lib';
|
||||
import {Injector, Inject, InjectLazy, bind} from 'angular2/di';
|
||||
import {Injector, Inject, InjectLazy, Optional, bind} from 'angular2/di';
|
||||
|
||||
class Engine {
|
||||
}
|
||||
@@ -34,6 +34,13 @@ class CarWithLazyEngine {
|
||||
}
|
||||
}
|
||||
|
||||
class CarWithOptionalEngine {
|
||||
engine;
|
||||
constructor(@Optional() engine:Engine) {
|
||||
this.engine = engine;
|
||||
}
|
||||
}
|
||||
|
||||
class CarWithDashboard {
|
||||
engine:Engine;
|
||||
dashboard:Dashboard;
|
||||
@@ -159,6 +166,15 @@ export function main() {
|
||||
expect(car.engine).toBeAnInstanceOf(Engine);
|
||||
});
|
||||
|
||||
it('should support optional dependencies', function () {
|
||||
var injector = new Injector([
|
||||
CarWithOptionalEngine
|
||||
]);
|
||||
|
||||
var car = injector.get(CarWithOptionalEngine);
|
||||
expect(car.engine).toEqual(null);
|
||||
});
|
||||
|
||||
it("should flatten passed-in bindings", function () {
|
||||
var injector = new Injector([
|
||||
[[Engine, Car]]
|
||||
|
||||
Reference in New Issue
Block a user