fix(di): throw if a token uses more than 20 dependencies.

Fixes #6690
Closes #6869
This commit is contained in:
Tobias Bosch
2016-02-03 09:51:24 -08:00
committed by Igor Minar
parent e73fee7156
commit de77700da0
2 changed files with 47 additions and 0 deletions
@@ -189,6 +189,49 @@ export function main() {
expect(car.engine).toBeAnInstanceOf(Engine);
});
it('should throw when using a factory with more than 20 dependencies', () => {
function factoryWithTooManyArgs() { return new Car(null); }
var injector = createInjector([
Engine,
provide(Car,
{
useFactory: factoryWithTooManyArgs,
deps: [
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine,
Engine
]
})
]);
try {
injector.get(Car);
throw "Must throw";
} catch (e) {
expect(e.message)
.toContain(`Cannot instantiate 'Car' because it has more than 20 dependencies`);
}
});
it('should supporting provider to null', () => {
var injector = createInjector([provide(Engine, {useValue: null})]);
var engine = injector.get(Engine);