fix(di): throw if a token uses more than 20 dependencies.
Fixes #6690 Closes #6869
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user