fix(ivy): ensure module imports are instantiated before the module being declared (#35172)

PR Close #35172
This commit is contained in:
Andrew Scott
2020-02-05 14:41:57 -08:00
committed by Misko Hevery
parent 79742a397f
commit 0cbdd54fd0
3 changed files with 49 additions and 6 deletions

View File

@ -267,6 +267,30 @@ describe('InjectorDef-based createInjector()', () => {
injector = createInjector(Module);
});
it('initializes imported modules before the module being declared', () => {
const moduleRegistrations: string[] = [];
class ChildModule {
static ɵinj = ɵɵdefineInjector({
factory: () => new ChildModule(),
imports: undefined,
providers: [],
});
constructor() { moduleRegistrations.push('ChildModule'); }
}
class RootModule {
static ɵinj = ɵɵdefineInjector({
factory: () => new RootModule(),
imports: [ChildModule],
providers: [],
});
constructor() { moduleRegistrations.push('RootModule'); }
}
createInjector(RootModule);
expect(moduleRegistrations).toEqual(['ChildModule', 'RootModule']);
});
it('injects a simple class', () => {
const instance = injector.get(Service);
expect(instance instanceof Service).toBeTruthy();