From 6c8638cf01d0466778211dfcf67fba5842b52324 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Fri, 10 Mar 2017 16:55:32 -0800 Subject: [PATCH] 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()); ``` --- packages/core/testing/src/test_bed.ts | 6 +++--- test-main.js | 12 ++++++++---- .../public_api_guard/core/typings/testing/index.d.ts | 6 +++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/core/testing/src/test_bed.ts b/packages/core/testing/src/test_bed.ts index 07a87fedb1..8fd8cca6ef 100644 --- a/packages/core/testing/src/test_bed.ts +++ b/packages/core/testing/src/test_bed.ts @@ -69,7 +69,7 @@ export class TestBed implements Injector { * * @experimental */ - static initTestEnvironment(ngModule: Type, platform: PlatformRef): TestBed { + static initTestEnvironment(ngModule: Type|Type[], platform: PlatformRef): TestBed { const testBed = getTestBed(); testBed.initTestEnvironment(ngModule, platform); return testBed; @@ -179,7 +179,7 @@ export class TestBed implements Injector { * * @experimental */ - initTestEnvironment(ngModule: Type, platform: PlatformRef) { + initTestEnvironment(ngModule: Type|Type[], platform: PlatformRef) { if (this.platform || this.ngModule) { 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; - ngModule: Type = null; + ngModule: Type|Type[] = null; configureCompiler(config: {providers?: any[], useJit?: boolean}) { this._assertNotInstantiated('TestBed.configureCompiler', 'configure the compiler'); diff --git a/test-main.js b/test-main.js index 9a510faf44..6130b6410d 100644 --- a/test-main.js +++ b/test-main.js @@ -66,11 +66,15 @@ System.config({ // method and kick off Karma (Jasmine). System.import('@angular/core/testing') .then(function(coreTesting) { - return System.import('@angular/platform-browser-dynamic/testing') - .then(function(browserTesting) { + return Promise + .all([ + System.import('@angular/platform-browser-dynamic/testing'), + System.import('@angular/platform-browser/animations') + ]) + .then(function(mods) { coreTesting.TestBed.initTestEnvironment( - browserTesting.BrowserDynamicTestingModule, - browserTesting.platformBrowserDynamicTesting()); + [mods[0].BrowserDynamicTestingModule, mods[1].NoopAnimationsModule], + mods[0].platformBrowserDynamicTesting()); }); }) .then(function() { diff --git a/tools/public_api_guard/core/typings/testing/index.d.ts b/tools/public_api_guard/core/typings/testing/index.d.ts index c993bb086a..f4d049268e 100644 --- a/tools/public_api_guard/core/typings/testing/index.d.ts +++ b/tools/public_api_guard/core/typings/testing/index.d.ts @@ -58,7 +58,7 @@ export declare function resetFakeAsyncZone(): void; /** @stable */ export declare class TestBed implements Injector { - ngModule: Type; + ngModule: Type | Type[]; platform: PlatformRef; compileComponents(): Promise; configureCompiler(config: { @@ -69,7 +69,7 @@ export declare class TestBed implements Injector { createComponent(component: Type): ComponentFixture; execute(tokens: any[], fn: Function, context?: any): any; get(token: any, notFoundValue?: any): any; - /** @experimental */ initTestEnvironment(ngModule: Type, platform: PlatformRef): void; + /** @experimental */ initTestEnvironment(ngModule: Type | Type[], platform: PlatformRef): void; overrideComponent(component: Type, override: MetadataOverride): void; overrideDirective(directive: Type, override: MetadataOverride): void; overrideModule(ngModule: Type, override: MetadataOverride): void; @@ -84,7 +84,7 @@ export declare class TestBed implements Injector { static configureTestingModule(moduleDef: TestModuleMetadata): typeof TestBed; static createComponent(component: Type): ComponentFixture; static get(token: any, notFoundValue?: any): any; - /** @experimental */ static initTestEnvironment(ngModule: Type, platform: PlatformRef): TestBed; + /** @experimental */ static initTestEnvironment(ngModule: Type | Type[], platform: PlatformRef): TestBed; static overrideComponent(component: Type, override: MetadataOverride): typeof TestBed; static overrideDirective(directive: Type, override: MetadataOverride): typeof TestBed; static overrideModule(ngModule: Type, override: MetadataOverride): typeof TestBed;