fix(testing): add an explicit doAsyncPrecompilation step (#10015)

This removes the magic from the `inject` test helper that would inspect
the current zone and would only work with our `async` test helper.
Now, `inject` is always synchronous, and if you are using a module
that requires async precompilation, you're required to call
`doAsyncPrecompilation` in your tests.

This is part of the breaking changes introduced with the swap
to each test having an AppModule.

Closes #9975
Closes #9593

BREAKING CHANGE:

`TestInjector` is now renamed to `TestBed`

Before:

```js
import {TestInjector, getTestInjector} from '@angular/core/testing';
```

After:

```js
import {TestBed, getTestBed} from '@angular/core/testing';
```
This commit is contained in:
Julie Ralph
2016-07-20 10:51:21 -07:00
committed by GitHub
parent 450f61d384
commit b43f95435b
10 changed files with 172 additions and 138 deletions

View File

@ -12,17 +12,17 @@
* allows tests to be asynchronous by either returning a promise or using a 'done' parameter.
*/
import {TestInjector, getTestInjector} from './test_injector';
import {TestBed, getTestBed} from './test_bed';
declare var global: any;
var _global = <any>(typeof window === 'undefined' ? global : window);
var testInjector: TestInjector = getTestInjector();
var testBed: TestBed = getTestBed();
// Reset the test providers before each test.
if (_global.beforeEach) {
_global.beforeEach(() => { testInjector.reset(); });
_global.beforeEach(() => { testBed.reset(); });
}
/**
@ -34,7 +34,7 @@ if (_global.beforeEach) {
export function addProviders(providers: Array<any>): void {
if (!providers) return;
try {
testInjector.configureModule({providers: providers});
testBed.configureModule({providers: providers});
} catch (e) {
throw new Error(
'addProviders can\'t be called after the injector has been already created for this test. ' +
@ -58,7 +58,7 @@ export function configureModule(moduleDef: {
}): void {
if (!moduleDef) return;
try {
testInjector.configureModule(moduleDef);
testBed.configureModule(moduleDef);
} catch (e) {
throw new Error(
'configureModule can\'t be called after the injector has been already created for this test. ' +
@ -76,7 +76,7 @@ export function configureModule(moduleDef: {
export function configureCompiler(config: {providers?: any[], useJit?: boolean}): void {
if (!config) return;
try {
testInjector.configureCompiler(config);
testBed.configureCompiler(config);
} catch (e) {
throw new Error(
'configureCompiler can\'t be called after the injector has been already created for this test. ' +