feat(test): Implement fakeAsync using the FakeAsyncTestZoneSpec from zone.js.

Update the version of zone.js to @0.6.12 that contains the new FakeAsyncTestZoneSpec.

The new fakeAsync zone handles errors better and clearPendingTimers() is no longer required to be called after handling an error and is deprecated.

The fakeAsync test zone will now throw an error if an XHR is attemtped within the test since that cannot be controlled synchronously in the test(Need to be mocked out with a service implementation that doesn't involve XHRs).

This commit also allows fakeAsync to wrap inject to make it consistent with async test zone.

BREAKING CHANGE:

inject can no longer wrap fakeAsync while fakeAsync can wrap inject. So the order in existing tests with inject and fakeAsync has to be switched as follows:

Before:
```
inject([...], fakeAsync((...) => {...}))
```

After:
```
fakeAsync(inject([...], (...) => {...}))
```

Closes #8142
This commit is contained in:
Vikram Subramanian
2016-04-18 16:04:35 -07:00
committed by vikerman
parent cc86fee1d1
commit bab81a9831
15 changed files with 448 additions and 520 deletions

View File

@ -195,7 +195,7 @@ function emptyArray(): Array<any> {
}
export class FunctionWithParamTokens {
constructor(private _tokens: any[], private _fn: Function, public isAsync: boolean,
constructor(private _tokens: any[], public fn: Function, public isAsync: boolean,
public additionalProviders: () => any = emptyArray) {}
/**
@ -203,7 +203,7 @@ export class FunctionWithParamTokens {
*/
execute(injector: ReflectiveInjector): any {
var params = this._tokens.map(t => injector.get(t));
return FunctionWrapper.apply(this._fn, params);
return FunctionWrapper.apply(this.fn, params);
}
hasToken(token: any): boolean { return this._tokens.indexOf(token) > -1; }