fix(ivy): ensure multi providers in ModuleWithProviders are not duplicated (#34914)

The current logic pulls multiproviders up to the parent module's
provider list. The result is that the multi provider being defined both in
the imported ModuleWithProviders and the parent and getting an extra
item in the multi provided array of values. This PR fixes that problem
by not pulling providers in ModuleWithProviders up to the parent module.

PR Close #34914
This commit is contained in:
Andrew Scott
2020-01-22 15:46:34 -08:00
committed by Andrew Kushnir
parent 0e76821045
commit 4975f89fdd
2 changed files with 20 additions and 12 deletions

View File

@ -394,15 +394,8 @@ export class R3TestBedCompiler {
const injectorDef: any = (moduleType as any)[NG_INJ_DEF];
if (this.providerOverridesByToken.size > 0) {
// Extract the list of providers from ModuleWithProviders, so we can define the final list of
// providers that might have overrides.
// Note: second `flatten` operation is needed to convert an array of providers
// (e.g. `[[], []]`) into one flat list, also eliminating empty arrays.
const providersFromModules = flatten(flatten(
injectorDef.imports, (imported: NgModuleType<any>| ModuleWithProviders<any>) =>
isModuleWithProviders(imported) ? imported.providers : []));
const providers = [
...providersFromModules, ...injectorDef.providers,
...injectorDef.providers,
...(this.providerOverridesByModule.get(moduleType as InjectorType<any>) || [])
];
if (this.hasProviderOverrides(providers)) {