feat(core): allow to provide multiple default testing modules (#15054)
This can be used to e.g. add the NoopAnimationsModule by default: ``` TestBed.initTestEnvironment([ BrowserDynamicTestingModule, NoopAnimationsModule ], platformBrowserDynamicTesting()); ```
This commit is contained in:
parent
8b5c6b2732
commit
6c8638cf01
|
@ -69,7 +69,7 @@ export class TestBed implements Injector {
|
||||||
*
|
*
|
||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
static initTestEnvironment(ngModule: Type<any>, platform: PlatformRef): TestBed {
|
static initTestEnvironment(ngModule: Type<any>|Type<any>[], platform: PlatformRef): TestBed {
|
||||||
const testBed = getTestBed();
|
const testBed = getTestBed();
|
||||||
testBed.initTestEnvironment(ngModule, platform);
|
testBed.initTestEnvironment(ngModule, platform);
|
||||||
return testBed;
|
return testBed;
|
||||||
|
@ -179,7 +179,7 @@ export class TestBed implements Injector {
|
||||||
*
|
*
|
||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
initTestEnvironment(ngModule: Type<any>, platform: PlatformRef) {
|
initTestEnvironment(ngModule: Type<any>|Type<any>[], platform: PlatformRef) {
|
||||||
if (this.platform || this.ngModule) {
|
if (this.platform || this.ngModule) {
|
||||||
throw new Error('Cannot set base providers because it has already been called');
|
throw new Error('Cannot set base providers because it has already been called');
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,7 @@ export class TestBed implements Injector {
|
||||||
|
|
||||||
platform: PlatformRef = null;
|
platform: PlatformRef = null;
|
||||||
|
|
||||||
ngModule: Type<any> = null;
|
ngModule: Type<any>|Type<any>[] = null;
|
||||||
|
|
||||||
configureCompiler(config: {providers?: any[], useJit?: boolean}) {
|
configureCompiler(config: {providers?: any[], useJit?: boolean}) {
|
||||||
this._assertNotInstantiated('TestBed.configureCompiler', 'configure the compiler');
|
this._assertNotInstantiated('TestBed.configureCompiler', 'configure the compiler');
|
||||||
|
|
12
test-main.js
12
test-main.js
|
@ -66,11 +66,15 @@ System.config({
|
||||||
// method and kick off Karma (Jasmine).
|
// method and kick off Karma (Jasmine).
|
||||||
System.import('@angular/core/testing')
|
System.import('@angular/core/testing')
|
||||||
.then(function(coreTesting) {
|
.then(function(coreTesting) {
|
||||||
return System.import('@angular/platform-browser-dynamic/testing')
|
return Promise
|
||||||
.then(function(browserTesting) {
|
.all([
|
||||||
|
System.import('@angular/platform-browser-dynamic/testing'),
|
||||||
|
System.import('@angular/platform-browser/animations')
|
||||||
|
])
|
||||||
|
.then(function(mods) {
|
||||||
coreTesting.TestBed.initTestEnvironment(
|
coreTesting.TestBed.initTestEnvironment(
|
||||||
browserTesting.BrowserDynamicTestingModule,
|
[mods[0].BrowserDynamicTestingModule, mods[1].NoopAnimationsModule],
|
||||||
browserTesting.platformBrowserDynamicTesting());
|
mods[0].platformBrowserDynamicTesting());
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
|
|
|
@ -58,7 +58,7 @@ export declare function resetFakeAsyncZone(): void;
|
||||||
|
|
||||||
/** @stable */
|
/** @stable */
|
||||||
export declare class TestBed implements Injector {
|
export declare class TestBed implements Injector {
|
||||||
ngModule: Type<any>;
|
ngModule: Type<any> | Type<any>[];
|
||||||
platform: PlatformRef;
|
platform: PlatformRef;
|
||||||
compileComponents(): Promise<any>;
|
compileComponents(): Promise<any>;
|
||||||
configureCompiler(config: {
|
configureCompiler(config: {
|
||||||
|
@ -69,7 +69,7 @@ export declare class TestBed implements Injector {
|
||||||
createComponent<T>(component: Type<T>): ComponentFixture<T>;
|
createComponent<T>(component: Type<T>): ComponentFixture<T>;
|
||||||
execute(tokens: any[], fn: Function, context?: any): any;
|
execute(tokens: any[], fn: Function, context?: any): any;
|
||||||
get(token: any, notFoundValue?: any): any;
|
get(token: any, notFoundValue?: any): any;
|
||||||
/** @experimental */ initTestEnvironment(ngModule: Type<any>, platform: PlatformRef): void;
|
/** @experimental */ initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef): void;
|
||||||
overrideComponent(component: Type<any>, override: MetadataOverride<Component>): void;
|
overrideComponent(component: Type<any>, override: MetadataOverride<Component>): void;
|
||||||
overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): void;
|
overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): void;
|
||||||
overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): void;
|
overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): void;
|
||||||
|
@ -84,7 +84,7 @@ export declare class TestBed implements Injector {
|
||||||
static configureTestingModule(moduleDef: TestModuleMetadata): typeof TestBed;
|
static configureTestingModule(moduleDef: TestModuleMetadata): typeof TestBed;
|
||||||
static createComponent<T>(component: Type<T>): ComponentFixture<T>;
|
static createComponent<T>(component: Type<T>): ComponentFixture<T>;
|
||||||
static get(token: any, notFoundValue?: any): any;
|
static get(token: any, notFoundValue?: any): any;
|
||||||
/** @experimental */ static initTestEnvironment(ngModule: Type<any>, platform: PlatformRef): TestBed;
|
/** @experimental */ static initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef): TestBed;
|
||||||
static overrideComponent(component: Type<any>, override: MetadataOverride<Component>): typeof TestBed;
|
static overrideComponent(component: Type<any>, override: MetadataOverride<Component>): typeof TestBed;
|
||||||
static overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): typeof TestBed;
|
static overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): typeof TestBed;
|
||||||
static overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): typeof TestBed;
|
static overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): typeof TestBed;
|
||||||
|
|
Loading…
Reference in New Issue