2016-06-30 13:07:17 -07:00
|
|
|
/**
|
|
|
|
|
* @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
|
|
|
|
|
*/
|
|
|
|
|
|
2016-07-08 10:47:17 -07:00
|
|
|
import {AppModuleFactory, AppModuleRef, bootstrapModuleFactory} from '@angular/core';
|
2016-06-30 13:07:17 -07:00
|
|
|
import {ComponentFixture} from '@angular/core/testing';
|
|
|
|
|
import {serverPlatform} from '@angular/platform-server';
|
|
|
|
|
|
|
|
|
|
import {MainModuleNgFactory} from '../src/module.ngfactory';
|
|
|
|
|
|
|
|
|
|
export function createModule<M>(factory: AppModuleFactory<M>): AppModuleRef<M> {
|
2016-07-08 10:47:17 -07:00
|
|
|
return bootstrapModuleFactory(factory, serverPlatform());
|
2016-06-30 13:07:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function createComponent<C>(
|
|
|
|
|
comp: {new (...args: any[]): C},
|
|
|
|
|
moduleFactory: AppModuleFactory<any> = null): ComponentFixture<C> {
|
|
|
|
|
if (!moduleFactory) {
|
|
|
|
|
moduleFactory = MainModuleNgFactory;
|
|
|
|
|
}
|
|
|
|
|
const moduleRef = createModule(moduleFactory);
|
|
|
|
|
const compRef =
|
|
|
|
|
moduleRef.componentFactoryResolver.resolveComponentFactory(comp).create(moduleRef.injector);
|
|
|
|
|
return new ComponentFixture(compRef, null, null);
|
|
|
|
|
}
|