| 
									
										
										
										
											2016-06-23 09:47:54 -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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-03 16:54:46 -08:00
										 |  |  | import {CompilerOptions, Component, Directive, InjectionToken, Injector, ModuleWithComponentFactories, NgModule, NgModuleRef, NgZone, Pipe, PlatformRef, Provider, ReflectiveInjector, SchemaMetadata, Type} from '@angular/core'; | 
					
						
							| 
									
										
										
										
											2016-12-09 13:04:18 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-26 13:06:50 -07:00
										 |  |  | import {AsyncTestCompleter} from './async_test_completer'; | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  | import {ComponentFixture} from './component_fixture'; | 
					
						
							| 
									
										
										
										
											2016-09-16 10:57:57 -07:00
										 |  |  | import {stringify} from './facade/lang'; | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  | import {MetadataOverride} from './metadata_override'; | 
					
						
							|  |  |  | import {TestingCompiler, TestingCompilerFactory} from './test_compiler'; | 
					
						
							| 
									
										
										
										
											2016-04-26 13:06:50 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  | const UNDEFINED = new Object(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * An abstract class for inserting the root test component element in a platform independent way. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @experimental | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | export class TestComponentRenderer { | 
					
						
							|  |  |  |   insertRootElement(rootElementId: string) {} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-16 10:57:57 -07:00
										 |  |  | let _nextRootElementId = 0; | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @experimental | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-01-03 16:54:46 -08:00
										 |  |  | export const ComponentFixtureAutoDetect = | 
					
						
							|  |  |  |     new InjectionToken<boolean[]>('ComponentFixtureAutoDetect'); | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @experimental | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-01-03 16:54:46 -08:00
										 |  |  | export const ComponentFixtureNoNgZone = new InjectionToken<boolean[]>('ComponentFixtureNoNgZone'); | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @experimental | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | export type TestModuleMetadata = { | 
					
						
							| 
									
										
										
										
											2016-09-16 10:57:57 -07:00
										 |  |  |   providers?: any[], | 
					
						
							|  |  |  |   declarations?: any[], | 
					
						
							|  |  |  |   imports?: any[], | 
					
						
							|  |  |  |   schemas?: Array<SchemaMetadata|any[]>, | 
					
						
							| 
									
										
										
										
											2016-08-30 18:07:40 -07:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2016-09-22 10:32:17 -07:00
										 |  |  |  * @whatItDoes Configures and initializes environment for unit testing and provides methods for | 
					
						
							|  |  |  |  * creating components and services in unit tests. | 
					
						
							|  |  |  |  * @description | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * TestBed is the primary api for writing unit tests for Angular applications and libraries. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @stable | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-07-20 10:51:21 -07:00
										 |  |  | export class TestBed implements Injector { | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Initialize the environment for testing with a compiler factory, a PlatformRef, and an | 
					
						
							|  |  |  |    * angular module. These are common to every test in the suite. | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * This may only be called once, to set up the common providers for the current test | 
					
						
							|  |  |  |    * suite on the current platform. If you absolutely need to change the providers, | 
					
						
							|  |  |  |    * first use `resetTestEnvironment`. | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * Test modules and platforms for individual platforms are available from | 
					
						
							| 
									
										
										
										
											2016-09-10 01:36:38 +09:00
										 |  |  |    * '@angular/<platform_name>/testing'. | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |    * | 
					
						
							|  |  |  |    * @experimental | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2016-08-10 18:21:28 -07:00
										 |  |  |   static initTestEnvironment(ngModule: Type<any>, platform: PlatformRef): TestBed { | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     const testBed = getTestBed(); | 
					
						
							| 
									
										
										
										
											2016-09-16 10:57:57 -07:00
										 |  |  |     testBed.initTestEnvironment(ngModule, platform); | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     return testBed; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Reset the providers for the test injector. | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * @experimental | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   static resetTestEnvironment() { getTestBed().resetTestEnvironment(); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static resetTestingModule(): typeof TestBed { | 
					
						
							|  |  |  |     getTestBed().resetTestingModule(); | 
					
						
							|  |  |  |     return TestBed; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Allows overriding default compiler providers and settings | 
					
						
							|  |  |  |    * which are defined in test_injector.js | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   static configureCompiler(config: {providers?: any[]; useJit?: boolean;}): typeof TestBed { | 
					
						
							|  |  |  |     getTestBed().configureCompiler(config); | 
					
						
							|  |  |  |     return TestBed; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Allows overriding default providers, directives, pipes, modules of the test injector, | 
					
						
							|  |  |  |    * which are defined in test_injector.js | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   static configureTestingModule(moduleDef: TestModuleMetadata): typeof TestBed { | 
					
						
							|  |  |  |     getTestBed().configureTestingModule(moduleDef); | 
					
						
							|  |  |  |     return TestBed; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Compile components with a `templateUrl` for the test's NgModule. | 
					
						
							|  |  |  |    * It is necessary to call this function | 
					
						
							|  |  |  |    * as fetching urls is asynchronous. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   static compileComponents(): Promise<any> { return getTestBed().compileComponents(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  |   static overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): typeof TestBed { | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     getTestBed().overrideModule(ngModule, override); | 
					
						
							|  |  |  |     return TestBed; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  |   static overrideComponent(component: Type<any>, override: MetadataOverride<Component>): | 
					
						
							| 
									
										
										
										
											2016-08-10 18:21:28 -07:00
										 |  |  |       typeof TestBed { | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     getTestBed().overrideComponent(component, override); | 
					
						
							|  |  |  |     return TestBed; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  |   static overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): | 
					
						
							| 
									
										
										
										
											2016-08-10 18:21:28 -07:00
										 |  |  |       typeof TestBed { | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     getTestBed().overrideDirective(directive, override); | 
					
						
							|  |  |  |     return TestBed; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  |   static overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): typeof TestBed { | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     getTestBed().overridePipe(pipe, override); | 
					
						
							|  |  |  |     return TestBed; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-15 02:05:17 +03:00
										 |  |  |   static overrideTemplate(component: Type<any>, template: string): typeof TestBed { | 
					
						
							|  |  |  |     getTestBed().overrideComponent(component, {set: {template, templateUrl: null}}); | 
					
						
							|  |  |  |     return TestBed; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-16 20:20:48 -07:00
										 |  |  |   static get(token: any, notFoundValue: any = Injector.THROW_IF_NOT_FOUND) { | 
					
						
							|  |  |  |     return getTestBed().get(token, notFoundValue); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-10 18:21:28 -07:00
										 |  |  |   static createComponent<T>(component: Type<T>): ComponentFixture<T> { | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     return getTestBed().createComponent(component); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-08 19:03:21 -08:00
										 |  |  |   private _instantiated: boolean = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |   private _compiler: TestingCompiler = null; | 
					
						
							| 
									
										
										
										
											2016-07-18 03:50:31 -07:00
										 |  |  |   private _moduleRef: NgModuleRef<any> = null; | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |   private _moduleWithComponentFactories: ModuleWithComponentFactories<any> = null; | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-18 03:50:31 -07:00
										 |  |  |   private _compilerOptions: CompilerOptions[] = []; | 
					
						
							| 
									
										
										
										
											2015-12-08 19:03:21 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  |   private _moduleOverrides: [Type<any>, MetadataOverride<NgModule>][] = []; | 
					
						
							|  |  |  |   private _componentOverrides: [Type<any>, MetadataOverride<Component>][] = []; | 
					
						
							|  |  |  |   private _directiveOverrides: [Type<any>, MetadataOverride<Directive>][] = []; | 
					
						
							|  |  |  |   private _pipeOverrides: [Type<any>, MetadataOverride<Pipe>][] = []; | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-15 19:37:42 -07:00
										 |  |  |   private _providers: Provider[] = []; | 
					
						
							| 
									
										
										
										
											2016-08-10 18:21:28 -07:00
										 |  |  |   private _declarations: Array<Type<any>|any[]|any> = []; | 
					
						
							|  |  |  |   private _imports: Array<Type<any>|any[]|any> = []; | 
					
						
							| 
									
										
										
										
											2016-07-25 03:02:57 -07:00
										 |  |  |   private _schemas: Array<SchemaMetadata|any[]> = []; | 
					
						
							| 
									
										
										
										
											2016-08-25 23:37:46 +02:00
										 |  |  |   private _activeFixtures: ComponentFixture<any>[] = []; | 
					
						
							| 
									
										
										
										
											2015-12-08 19:03:21 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |   /** | 
					
						
							|  |  |  |    * Initialize the environment for testing with a compiler factory, a PlatformRef, and an | 
					
						
							|  |  |  |    * angular module. These are common to every test in the suite. | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * This may only be called once, to set up the common providers for the current test | 
					
						
							|  |  |  |    * suite on the current platform. If you absolutely need to change the providers, | 
					
						
							|  |  |  |    * first use `resetTestEnvironment`. | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * Test modules and platforms for individual platforms are available from | 
					
						
							| 
									
										
										
										
											2016-09-10 01:36:38 +09:00
										 |  |  |    * '@angular/<platform_name>/testing'. | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |    * | 
					
						
							|  |  |  |    * @experimental | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2016-08-10 18:21:28 -07:00
										 |  |  |   initTestEnvironment(ngModule: Type<any>, platform: PlatformRef) { | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     if (this.platform || this.ngModule) { | 
					
						
							| 
									
										
										
										
											2016-08-25 00:50:16 -07:00
										 |  |  |       throw new Error('Cannot set base providers because it has already been called'); | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     } | 
					
						
							|  |  |  |     this.platform = platform; | 
					
						
							|  |  |  |     this.ngModule = ngModule; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Reset the providers for the test injector. | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * @experimental | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   resetTestEnvironment() { | 
					
						
							|  |  |  |     this.resetTestingModule(); | 
					
						
							|  |  |  |     this.platform = null; | 
					
						
							|  |  |  |     this.ngModule = null; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   resetTestingModule() { | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  |     this._compiler = null; | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     this._moduleOverrides = []; | 
					
						
							|  |  |  |     this._componentOverrides = []; | 
					
						
							|  |  |  |     this._directiveOverrides = []; | 
					
						
							|  |  |  |     this._pipeOverrides = []; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  |     this._moduleRef = null; | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     this._moduleWithComponentFactories = null; | 
					
						
							| 
									
										
										
										
											2016-07-18 03:50:31 -07:00
										 |  |  |     this._compilerOptions = []; | 
					
						
							| 
									
										
										
										
											2015-12-08 19:03:21 -08:00
										 |  |  |     this._providers = []; | 
					
						
							| 
									
										
										
										
											2016-07-18 03:50:31 -07:00
										 |  |  |     this._declarations = []; | 
					
						
							|  |  |  |     this._imports = []; | 
					
						
							| 
									
										
										
										
											2016-07-25 03:02:57 -07:00
										 |  |  |     this._schemas = []; | 
					
						
							| 
									
										
										
										
											2015-12-08 19:03:21 -08:00
										 |  |  |     this._instantiated = false; | 
					
						
							| 
									
										
										
										
											2016-08-25 23:37:46 +02:00
										 |  |  |     this._activeFixtures.forEach((fixture) => fixture.destroy()); | 
					
						
							|  |  |  |     this._activeFixtures = []; | 
					
						
							| 
									
										
										
										
											2015-12-08 19:03:21 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  |   platform: PlatformRef = null; | 
					
						
							| 
									
										
										
										
											2015-12-15 16:38:27 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-10 18:21:28 -07:00
										 |  |  |   ngModule: Type<any> = null; | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   configureCompiler(config: {providers?: any[], useJit?: boolean}) { | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     this._assertNotInstantiated('TestBed.configureCompiler', 'configure the compiler'); | 
					
						
							| 
									
										
										
										
											2016-07-18 03:50:31 -07:00
										 |  |  |     this._compilerOptions.push(config); | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-12-15 16:38:27 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |   configureTestingModule(moduleDef: TestModuleMetadata) { | 
					
						
							|  |  |  |     this._assertNotInstantiated('TestBed.configureTestingModule', 'configure the test module'); | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  |     if (moduleDef.providers) { | 
					
						
							| 
									
										
										
										
											2016-09-16 10:57:57 -07:00
										 |  |  |       this._providers.push(...moduleDef.providers); | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-07-18 03:50:31 -07:00
										 |  |  |     if (moduleDef.declarations) { | 
					
						
							| 
									
										
										
										
											2016-09-16 10:57:57 -07:00
										 |  |  |       this._declarations.push(...moduleDef.declarations); | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-07-18 03:50:31 -07:00
										 |  |  |     if (moduleDef.imports) { | 
					
						
							| 
									
										
										
										
											2016-09-16 10:57:57 -07:00
										 |  |  |       this._imports.push(...moduleDef.imports); | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-07-25 03:02:57 -07:00
										 |  |  |     if (moduleDef.schemas) { | 
					
						
							| 
									
										
										
										
											2016-09-16 10:57:57 -07:00
										 |  |  |       this._schemas.push(...moduleDef.schemas); | 
					
						
							| 
									
										
										
										
											2016-07-25 03:02:57 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-12-08 19:03:21 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |   compileComponents(): Promise<any> { | 
					
						
							|  |  |  |     if (this._moduleWithComponentFactories || this._instantiated) { | 
					
						
							|  |  |  |       return Promise.resolve(null); | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-07-20 10:51:21 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-18 03:50:31 -07:00
										 |  |  |     const moduleType = this._createCompilerAndModule(); | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     return this._compiler.compileModuleAndAllComponentsAsync(moduleType) | 
					
						
							|  |  |  |         .then((moduleAndComponentFactories) => { | 
					
						
							|  |  |  |           this._moduleWithComponentFactories = moduleAndComponentFactories; | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |   private _initIfNeeded() { | 
					
						
							| 
									
										
										
										
											2016-07-20 10:51:21 -07:00
										 |  |  |     if (this._instantiated) { | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     if (!this._moduleWithComponentFactories) { | 
					
						
							|  |  |  |       try { | 
					
						
							| 
									
										
										
										
											2016-11-12 14:08:58 +01:00
										 |  |  |         const moduleType = this._createCompilerAndModule(); | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |         this._moduleWithComponentFactories = | 
					
						
							|  |  |  |             this._compiler.compileModuleAndAllComponentsSync(moduleType); | 
					
						
							|  |  |  |       } catch (e) { | 
					
						
							| 
									
										
										
										
											2016-08-25 00:50:16 -07:00
										 |  |  |         if (e.compType) { | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |           throw new Error( | 
					
						
							| 
									
										
										
										
											2016-12-22 23:35:57 +03:00
										 |  |  |               `This test module uses the component ${stringify(e.compType)} which is using a "templateUrl" or "styleUrls", but they were never compiled. ` + | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |               `Please call "TestBed.compileComponents" before your test.`); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |           throw e; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-12-09 13:04:18 -08:00
										 |  |  |     const ngZone = new NgZone({enableLongStackTrace: true}); | 
					
						
							|  |  |  |     const ngZoneInjector = ReflectiveInjector.resolveAndCreate( | 
					
						
							|  |  |  |         [{provide: NgZone, useValue: ngZone}], this.platform.injector); | 
					
						
							|  |  |  |     this._moduleRef = this._moduleWithComponentFactories.ngModuleFactory.create(ngZoneInjector); | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     this._instantiated = true; | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-10 18:21:28 -07:00
										 |  |  |   private _createCompilerAndModule(): Type<any> { | 
					
						
							| 
									
										
										
										
											2016-07-18 03:50:31 -07:00
										 |  |  |     const providers = this._providers.concat([{provide: TestBed, useValue: this}]); | 
					
						
							|  |  |  |     const declarations = this._declarations; | 
					
						
							|  |  |  |     const imports = [this.ngModule, this._imports]; | 
					
						
							| 
									
										
										
										
											2016-07-25 03:02:57 -07:00
										 |  |  |     const schemas = this._schemas; | 
					
						
							| 
									
										
										
										
											2016-07-18 03:50:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     @NgModule( | 
					
						
							|  |  |  |         {providers: providers, declarations: declarations, imports: imports, schemas: schemas}) | 
					
						
							| 
									
										
										
										
											2016-07-18 03:50:31 -07:00
										 |  |  |     class DynamicTestModule { | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     const compilerFactory: TestingCompilerFactory = | 
					
						
							|  |  |  |         this.platform.injector.get(TestingCompilerFactory); | 
					
						
							| 
									
										
										
										
											2016-07-18 03:50:31 -07:00
										 |  |  |     this._compiler = | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |         compilerFactory.createTestingCompiler(this._compilerOptions.concat([{useDebug: true}])); | 
					
						
							|  |  |  |     this._moduleOverrides.forEach((entry) => this._compiler.overrideModule(entry[0], entry[1])); | 
					
						
							|  |  |  |     this._componentOverrides.forEach( | 
					
						
							|  |  |  |         (entry) => this._compiler.overrideComponent(entry[0], entry[1])); | 
					
						
							|  |  |  |     this._directiveOverrides.forEach( | 
					
						
							|  |  |  |         (entry) => this._compiler.overrideDirective(entry[0], entry[1])); | 
					
						
							|  |  |  |     this._pipeOverrides.forEach((entry) => this._compiler.overridePipe(entry[0], entry[1])); | 
					
						
							| 
									
										
										
										
											2016-07-18 03:50:31 -07:00
										 |  |  |     return DynamicTestModule; | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |   private _assertNotInstantiated(methodName: string, methodDescription: string) { | 
					
						
							|  |  |  |     if (this._instantiated) { | 
					
						
							| 
									
										
										
										
											2016-08-25 00:50:16 -07:00
										 |  |  |       throw new Error( | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |           `Cannot ${methodDescription} when the test module has already been instantiated. ` + | 
					
						
							|  |  |  |           `Make sure you are not using \`inject\` before \`${methodName}\`.`); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-12-08 19:03:21 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  |   get(token: any, notFoundValue: any = Injector.THROW_IF_NOT_FOUND) { | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     this._initIfNeeded(); | 
					
						
							| 
									
										
										
										
											2016-07-20 10:51:21 -07:00
										 |  |  |     if (token === TestBed) { | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  |       return this; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-07-18 03:50:31 -07:00
										 |  |  |     // Tests can inject things from the ng module and from the compiler,
 | 
					
						
							|  |  |  |     // but the ng module can't inject things from the compiler and vice versa.
 | 
					
						
							| 
									
										
										
										
											2016-09-16 10:57:57 -07:00
										 |  |  |     const result = this._moduleRef.injector.get(token, UNDEFINED); | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     return result === UNDEFINED ? this._compiler.injector.get(token, notFoundValue) : result; | 
					
						
							| 
									
										
										
										
											2016-04-26 13:06:50 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   execute(tokens: any[], fn: Function): any { | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     this._initIfNeeded(); | 
					
						
							| 
									
										
										
										
											2016-09-16 10:57:57 -07:00
										 |  |  |     const params = tokens.map(t => this.get(t)); | 
					
						
							|  |  |  |     return fn(...params); | 
					
						
							| 
									
										
										
										
											2015-12-08 19:03:21 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  |   overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): void { | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     this._assertNotInstantiated('overrideModule', 'override module metadata'); | 
					
						
							|  |  |  |     this._moduleOverrides.push([ngModule, override]); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  |   overrideComponent(component: Type<any>, override: MetadataOverride<Component>): void { | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     this._assertNotInstantiated('overrideComponent', 'override component metadata'); | 
					
						
							|  |  |  |     this._componentOverrides.push([component, override]); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  |   overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): void { | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     this._assertNotInstantiated('overrideDirective', 'override directive metadata'); | 
					
						
							|  |  |  |     this._directiveOverrides.push([directive, override]); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-12 09:44:20 -07:00
										 |  |  |   overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): void { | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     this._assertNotInstantiated('overridePipe', 'override pipe metadata'); | 
					
						
							|  |  |  |     this._pipeOverrides.push([pipe, override]); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-10 18:21:28 -07:00
										 |  |  |   createComponent<T>(component: Type<T>): ComponentFixture<T> { | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     this._initIfNeeded(); | 
					
						
							|  |  |  |     const componentFactory = this._moduleWithComponentFactories.componentFactories.find( | 
					
						
							|  |  |  |         (compFactory) => compFactory.componentType === component); | 
					
						
							|  |  |  |     if (!componentFactory) { | 
					
						
							| 
									
										
										
										
											2016-08-25 00:50:16 -07:00
										 |  |  |       throw new Error( | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |           `Cannot create the component ${stringify(component)} as it was not imported into the testing module!`); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     const noNgZone = this.get(ComponentFixtureNoNgZone, false); | 
					
						
							|  |  |  |     const autoDetect: boolean = this.get(ComponentFixtureAutoDetect, false); | 
					
						
							|  |  |  |     const ngZone: NgZone = noNgZone ? null : this.get(NgZone, null); | 
					
						
							|  |  |  |     const testComponentRenderer: TestComponentRenderer = this.get(TestComponentRenderer); | 
					
						
							|  |  |  |     const rootElId = `root${_nextRootElementId++}`; | 
					
						
							|  |  |  |     testComponentRenderer.insertRootElement(rootElId); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const initComponent = () => { | 
					
						
							| 
									
										
										
										
											2016-09-16 10:57:57 -07:00
										 |  |  |       const componentRef = componentFactory.create(this, [], `#${rootElId}`); | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |       return new ComponentFixture<T>(componentRef, ngZone, autoDetect); | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-16 10:57:57 -07:00
										 |  |  |     const fixture = !ngZone ? initComponent() : ngZone.run(initComponent); | 
					
						
							| 
									
										
										
										
											2016-08-25 23:37:46 +02:00
										 |  |  |     this._activeFixtures.push(fixture); | 
					
						
							|  |  |  |     return fixture; | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-12-08 19:03:21 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-16 10:57:57 -07:00
										 |  |  | let _testBed: TestBed = null; | 
					
						
							| 
									
										
										
										
											2015-12-08 19:03:21 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-27 12:27:23 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @experimental | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-07-20 10:51:21 -07:00
										 |  |  | export function getTestBed() { | 
					
						
							| 
									
										
										
										
											2016-09-16 10:57:57 -07:00
										 |  |  |   return _testBed = _testBed || new TestBed(); | 
					
						
							| 
									
										
										
										
											2016-07-20 10:51:21 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-13 20:52:59 +00:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2015-12-08 16:44:04 -08:00
										 |  |  |  * Allows injecting dependencies in `beforeEach()` and `it()`. | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Example: | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2015-03-13 18:48:29 +01:00
										 |  |  |  * ```
 | 
					
						
							|  |  |  |  * beforeEach(inject([Dependency, AClass], (dep, object) => { | 
					
						
							|  |  |  |  *   // some code that uses `dep` and `object`
 | 
					
						
							|  |  |  |  *   // ...
 | 
					
						
							|  |  |  |  * })); | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2015-11-18 18:46:24 -08:00
										 |  |  |  * it('...', inject([AClass], (object) => { | 
					
						
							| 
									
										
										
										
											2015-12-08 16:44:04 -08:00
										 |  |  |  *   object.doSomething(); | 
					
						
							|  |  |  |  *   expect(...); | 
					
						
							| 
									
										
										
										
											2015-03-13 18:48:29 +01:00
										 |  |  |  * }) | 
					
						
							|  |  |  |  * ```
 | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Notes: | 
					
						
							| 
									
										
										
										
											2015-12-08 19:03:21 -08:00
										 |  |  |  * - inject is currently a function because of some Traceur limitation the syntax should | 
					
						
							|  |  |  |  * eventually | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |  *   becomes `it('...', @Inject (object: AClass, async: AsyncTestCompleter) => { ... });` | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2016-06-27 12:27:23 -07:00
										 |  |  |  * @stable | 
					
						
							| 
									
										
										
										
											2015-03-13 11:10:11 +01:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
											
												refactor(testing): remove wrapping of Jasmine functions (#9564)
Instead, the async function now determines whether it should return a promise
or instead call a done function parameter. Importing Jasmine functions
from `@angular/core/testing` is no longer necessary and is now deprecated.
Additionally, beforeEachProviders is also deprecated, as it is specific
to the testing framework. Instead, use the new addProviders method directly.
Before:
```js
import {beforeEachProviders, it, describe, inject} from 'angular2/testing/core';
describe('my code', () => {
  beforeEachProviders(() => [MyService]);
  it('does stuff', inject([MyService], (service) => {
    // actual test
  });
});
```
After:
```js
import {addProviders, inject} from 'angular2/testing/core';
describe('my code', () => {
  beforeEach(() => {
    addProviders([MyService]);
  });
  it('does stuff', inject([MyService], (service) => {
    // actual test
  });
});
```
											
										 
											2016-06-24 17:48:35 -07:00
										 |  |  | export function inject(tokens: any[], fn: Function): () => any { | 
					
						
							| 
									
										
										
										
											2016-09-16 10:57:57 -07:00
										 |  |  |   const testBed = getTestBed(); | 
					
						
							| 
									
										
										
										
											2016-04-26 13:06:50 -07:00
										 |  |  |   if (tokens.indexOf(AsyncTestCompleter) >= 0) { | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     return () => | 
					
						
							|  |  |  |                // Return an async test method that returns a Promise if AsyncTestCompleter is one of
 | 
					
						
							|  |  |  |         // the
 | 
					
						
							|  |  |  |         // injected tokens.
 | 
					
						
							|  |  |  |         testBed.compileComponents().then(() => { | 
					
						
							| 
									
										
										
										
											2016-09-16 10:57:57 -07:00
										 |  |  |           const completer: AsyncTestCompleter = testBed.get(AsyncTestCompleter); | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |           testBed.execute(tokens, fn); | 
					
						
							|  |  |  |           return completer.promise; | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2016-04-26 13:06:50 -07:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     return () => testBed.execute(tokens, fn); | 
					
						
							| 
									
										
										
										
											2016-04-26 13:06:50 -07:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-27 12:27:23 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @experimental | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-12-10 12:00:48 -08:00
										 |  |  | export class InjectSetupWrapper { | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |   constructor(private _moduleDef: () => TestModuleMetadata) {} | 
					
						
							| 
									
										
										
										
											2015-12-10 12:00:48 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  |   private _addModule() { | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |     const moduleDef = this._moduleDef(); | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  |     if (moduleDef) { | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  |       getTestBed().configureTestingModule(moduleDef); | 
					
						
							| 
									
										
										
										
											2016-04-26 13:06:50 -07:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												refactor(testing): remove wrapping of Jasmine functions (#9564)
Instead, the async function now determines whether it should return a promise
or instead call a done function parameter. Importing Jasmine functions
from `@angular/core/testing` is no longer necessary and is now deprecated.
Additionally, beforeEachProviders is also deprecated, as it is specific
to the testing framework. Instead, use the new addProviders method directly.
Before:
```js
import {beforeEachProviders, it, describe, inject} from 'angular2/testing/core';
describe('my code', () => {
  beforeEachProviders(() => [MyService]);
  it('does stuff', inject([MyService], (service) => {
    // actual test
  });
});
```
After:
```js
import {addProviders, inject} from 'angular2/testing/core';
describe('my code', () => {
  beforeEach(() => {
    addProviders([MyService]);
  });
  it('does stuff', inject([MyService], (service) => {
    // actual test
  });
});
```
											
										 
											2016-06-24 17:48:35 -07:00
										 |  |  |   inject(tokens: any[], fn: Function): () => any { | 
					
						
							| 
									
										
										
										
											2016-04-26 13:06:50 -07:00
										 |  |  |     return () => { | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  |       this._addModule(); | 
					
						
							| 
									
										
										
										
											2016-07-20 10:51:21 -07:00
										 |  |  |       return inject(tokens, fn)(); | 
					
						
							| 
									
										
										
										
											2016-05-26 13:33:53 -07:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2015-12-10 12:00:48 -08:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												feat(testing): add implicit test module
Every test now has an implicit module. It can be configured via `configureModule` (from @angular/core/testing)
to add providers, directives, pipes, ...
The compiler now has to be configured separately via `configureCompiler` (from @angular/core/testing)
to add providers or define whether to use jit.
BREAKING CHANGE:
- Application providers can no longer inject compiler internals (i.e. everything
  from `@angular/compiler). Inject `Compiler` instead. This reflects the
  changes to `bootstrap` for module support (3f55aa609f60f130f1d69188ed057214b1267cb3).
- Compiler providers can no longer be added via `addProviders` / `withProviders`.
  Use the new method `configureCompiler` instead.
- Platform directives / pipes need to be provided via
  `configureModule` and can no longer be provided via the
  `PLATFORM_PIPES` / `PLATFORM_DIRECTIVES` tokens.
- `setBaseTestProviders()` was renamed into `initTestEnvironment` and 
  now takes a `PlatformRef` and a factory for a
  `Compiler`.
- E.g. for the browser platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS} from ‘@angular/platform-browser-dynamic/testing’;
  
  setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
      TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {browserTestCompiler, browserDynamicTestPlatform,
      BrowserDynamicTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      browserTestCompiler,
      browserDynamicTestPlatform(),
      BrowserDynamicTestModule);
  ```
- E.g. for the server platform:
  
  BEFORE:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS} from ‘@angular/platform-server/testing/server’;
  
  setBaseTestProviders(TEST_SERVER_PLATFORM_PROVIDERS,
      TEST_SERVER_APPLICATION_PROVIDERS);   
  ```
  AFTER:
  ```
  import {setBaseTestProviders} from ‘@angular/core/testing’;
  import {serverTestCompiler, serverTestPlatform,
      ServerTestModule} from ‘@angular/platform-browser-dynamic/testing’;
  
  initTestEnvironment(
      serverTestCompiler,
      serverTestPlatform(),
      ServerTestModule);
  ```
Related to #9726
Closes #9846
											
										 
											2016-07-04 09:37:30 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @experimental | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-07-28 04:54:49 -07:00
										 |  |  | export function withModule(moduleDef: TestModuleMetadata): InjectSetupWrapper; | 
					
						
							|  |  |  | export function withModule(moduleDef: TestModuleMetadata, fn: Function): () => any; | 
					
						
							|  |  |  | export function withModule(moduleDef: TestModuleMetadata, fn: Function = null): (() => any)| | 
					
						
							|  |  |  |     InjectSetupWrapper { | 
					
						
							|  |  |  |   if (fn) { | 
					
						
							|  |  |  |     return () => { | 
					
						
							|  |  |  |       const testBed = getTestBed(); | 
					
						
							|  |  |  |       if (moduleDef) { | 
					
						
							|  |  |  |         testBed.configureTestingModule(moduleDef); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       return fn(); | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return new InjectSetupWrapper(() => moduleDef); | 
					
						
							| 
									
										
										
										
											2015-12-10 12:00:48 -08:00
										 |  |  | } |