fix(ivy): TestBed not unwrapping imports array function when overriding provider (#34629)
Fixes an error that is thrown when a provider is overridden in `TestBed`, if the module definition of one of the imported modules uses a function for the `imports` that is set via `setNgModuleScope`. The problem was that we have a `for...of` loop that assumes that the imports are an array, but they can also be a function. This was handled correctly in other places, but this one was missed. Note that the above-mentioned error is only thrown at runtime when the code is transpiled to es6. In es5 TS generates a call to a helper that handles the error silently so the attached unit test only fails in es6. Fixes #34623. PR Close #34629
This commit is contained in:

committed by
Alex Rickabaugh

parent
7a0d6e7cba
commit
963ed711d8
@ -413,8 +413,9 @@ export class R3TestBedCompiler {
|
||||
}
|
||||
|
||||
// Apply provider overrides to imported modules recursively
|
||||
const moduleDef: any = (moduleType as any)[NG_MOD_DEF];
|
||||
for (const importedModule of moduleDef.imports) {
|
||||
const moduleDef = (moduleType as any)[NG_MOD_DEF];
|
||||
const imports = maybeUnwrapFn(moduleDef.imports);
|
||||
for (const importedModule of imports) {
|
||||
this.applyProviderOverridesToModule(importedModule);
|
||||
}
|
||||
// Also override the providers on any ModuleWithProviders imports since those don't appear in
|
||||
|
Reference in New Issue
Block a user