refactor(testing): introduce new testing api to support ng modules
BREAKING CHANGE: - deprecations: * `withProviders`, use `TestBed.withModule` instead * `addProviders`, use `TestBed.configureTestingModule` instead * `TestComponentBuilder`, use `TestBed.configureTestModule` / `TestBed.override...` / `TestBed.createComponent` instead. Closes #10354
This commit is contained in:
@ -7,10 +7,9 @@
|
||||
*/
|
||||
|
||||
import {Injector, OpaqueToken} from '../di';
|
||||
import {BaseException} from '../facade/exceptions';
|
||||
import {BaseException, unimplemented} from '../facade/exceptions';
|
||||
import {ConcreteType, Type, stringify} from '../facade/lang';
|
||||
import {ViewEncapsulation} from '../metadata';
|
||||
import {NgModuleMetadata} from '../metadata/ng_module';
|
||||
import {NgModuleMetadata, ViewEncapsulation} from '../metadata';
|
||||
|
||||
import {ComponentFactory} from './component_factory';
|
||||
import {ComponentResolver} from './component_resolver';
|
||||
@ -28,6 +27,22 @@ export class ComponentStillLoadingError extends BaseException {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Combination of NgModuleFactory and ComponentFactorys.
|
||||
*
|
||||
* @experimental
|
||||
*/
|
||||
export class ModuleWithComponentFactories<T> {
|
||||
constructor(
|
||||
public ngModuleFactory: NgModuleFactory<T>,
|
||||
public componentFactories: ComponentFactory<any>[]) {}
|
||||
}
|
||||
|
||||
|
||||
function _throwError() {
|
||||
throw new BaseException(`Runtime compiler is not loaded`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Low-level service for running the angular compiler duirng runtime
|
||||
* to create {@link ComponentFactory}s, which
|
||||
@ -39,42 +54,48 @@ export class ComponentStillLoadingError extends BaseException {
|
||||
* @stable
|
||||
*/
|
||||
export class Compiler {
|
||||
/**
|
||||
* Returns the injector with which the compiler has been created.
|
||||
*/
|
||||
get _injector(): Injector {
|
||||
throw new BaseException(`Runtime compiler is not loaded. Tried to read the injector.`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the template and styles of a component and returns the associated `ComponentFactory`.
|
||||
*/
|
||||
compileComponentAsync<T>(component: ConcreteType<T>, ngModule: Type = null):
|
||||
Promise<ComponentFactory<T>> {
|
||||
throw new BaseException(
|
||||
`Runtime compiler is not loaded. Tried to compile ${stringify(component)}`);
|
||||
throw _throwError();
|
||||
}
|
||||
/**
|
||||
* Compiles the given component. All templates have to be either inline or compiled via
|
||||
* `compileComponentAsync` before. Otherwise throws a {@link ComponentStillLoadingError}.
|
||||
*/
|
||||
compileComponentSync<T>(component: ConcreteType<T>, ngModule: Type = null): ComponentFactory<T> {
|
||||
throw new BaseException(
|
||||
`Runtime compiler is not loaded. Tried to compile ${stringify(component)}`);
|
||||
throw _throwError();
|
||||
}
|
||||
/**
|
||||
* Compiles the given NgModule. All templates of the components listed in `entryComponents`
|
||||
* have to be either inline or compiled before via `compileComponentAsync` /
|
||||
* `compileModuleAsync`. Otherwise throws a {@link ComponentStillLoadingError}.
|
||||
* Compiles the given NgModule and all of its components. All templates of the components listed
|
||||
* in `entryComponents`
|
||||
* have to be inlined. Otherwise throws a {@link ComponentStillLoadingError}.
|
||||
*/
|
||||
compileModuleSync<T>(moduleType: ConcreteType<T>): NgModuleFactory<T> {
|
||||
throw new BaseException(
|
||||
`Runtime compiler is not loaded. Tried to compile ${stringify(moduleType)}`);
|
||||
compileModuleSync<T>(moduleType: ConcreteType<T>): NgModuleFactory<T> { throw _throwError(); }
|
||||
|
||||
/**
|
||||
* Compiles the given NgModule and all of its components
|
||||
*/
|
||||
compileModuleAsync<T>(moduleType: ConcreteType<T>): Promise<NgModuleFactory<T>> {
|
||||
throw _throwError();
|
||||
}
|
||||
|
||||
compileModuleAsync<T>(moduleType: ConcreteType<T>): Promise<NgModuleFactory<T>> {
|
||||
throw new BaseException(
|
||||
`Runtime compiler is not loaded. Tried to compile ${stringify(moduleType)}`);
|
||||
/**
|
||||
* Same as {@link compileModuleSync} put also creates ComponentFactories for all components.
|
||||
*/
|
||||
compileModuleAndAllComponentsSync<T>(moduleType: ConcreteType<T>):
|
||||
ModuleWithComponentFactories<T> {
|
||||
throw _throwError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link compileModuleAsync} put also creates ComponentFactories for all components.
|
||||
*/
|
||||
compileModuleAndAllComponentsAsync<T>(moduleType: ConcreteType<T>):
|
||||
Promise<ModuleWithComponentFactories<T>> {
|
||||
throw _throwError();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user