feat(testing): use zones to avoid the need for injectAsync

Use a zone counting timeouts and microtasks to determine when a test
is finished, instead of requiring the test writer to use
injectAsync and return a promise.

See #5322
This commit is contained in:
Julie Ralph
2015-11-18 18:46:24 -08:00
committed by vsavkin
parent a8c3b9d67c
commit 0c9596ae2b
3 changed files with 204 additions and 117 deletions

View File

@ -123,7 +123,9 @@ export function createTestInjector(providers: Array<Type | Provider | any[]>): I
}
/**
* Allows injecting dependencies in `beforeEach()` and `it()`.
* Allows injecting dependencies in `beforeEach()` and `it()`. When using with the
* `angular2/testing` library, the test function will be run within a zone and will
* automatically complete when all asynchronous tests have finished.
*
* Example:
*
@ -133,17 +135,14 @@ export function createTestInjector(providers: Array<Type | Provider | any[]>): I
* // ...
* }));
*
* it('...', inject([AClass, AsyncTestCompleter], (object, async) => {
* it('...', inject([AClass], (object) => {
* object.doSomething().then(() => {
* expect(...);
* async.done();
* });
* })
* ```
*
* Notes:
* - injecting an `AsyncTestCompleter` allow completing async tests - this is the equivalent of
* adding a `done` parameter in Jasmine,
* - inject is currently a function because of some Traceur limitation the syntax should eventually
* becomes `it('...', @Inject (object: AClass, async: AsyncTestCompleter) => { ... });`
*
@ -155,6 +154,9 @@ export function inject(tokens: any[], fn: Function): FunctionWithParamTokens {
return new FunctionWithParamTokens(tokens, fn, false);
}
/**
* @deprecated Use inject instead, which now supports both synchronous and asynchronous tests.
*/
export function injectAsync(tokens: any[], fn: Function): FunctionWithParamTokens {
return new FunctionWithParamTokens(tokens, fn, true);
}