This makes `bootstrapModuleFactory` wait for promises returned by `APP_INITIALIZER`s, also making `bootstrapModuleFactory` async. I.e. now `bootstrapModule` and `bootstrapModuleFactory` behave in the same way. This ensures that all code from module instantiation, to creating `ApplicationRef`s as well as calling `APP_INITIALIZERS` is run in the Angular zone. This also moves the invocation of the initializers from the `ApplicationRef` constructor into the `bootstrapModuleFactory` call, allowing initializers to get a hold of `ApplicationRef` (see #9101). Fixes #9101 Fixes #10363 Fixes #10205
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
|
|
import {NgModuleFactory, NgModuleRef} from '@angular/core';
|
|
import {ComponentFixture} from '@angular/core/testing';
|
|
import {serverPlatform} from '@angular/platform-server';
|
|
|
|
import {MainModule} from '../src/module';
|
|
import {MainModuleNgFactory} from '../src/module.ngfactory';
|
|
|
|
let mainModuleRef: NgModuleRef<MainModule> = null;
|
|
beforeEach((done) => {
|
|
serverPlatform().bootstrapModuleFactory(MainModuleNgFactory).then((moduleRef) => {
|
|
mainModuleRef = moduleRef;
|
|
done();
|
|
});
|
|
});
|
|
|
|
export function createModule(): NgModuleRef<MainModule> {
|
|
return mainModuleRef;
|
|
}
|
|
|
|
export function createComponent<C>(comp: {new (...args: any[]): C}): ComponentFixture<C> {
|
|
const moduleRef = createModule();
|
|
const compRef =
|
|
moduleRef.componentFactoryResolver.resolveComponentFactory(comp).create(moduleRef.injector);
|
|
return new ComponentFixture(compRef, null, null);
|
|
}
|