| 
									
										
										
										
											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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												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
										 |  |  | import {addProviders, inject, fakeAsync, async, withProviders, tick,} from '@angular/core/testing'; | 
					
						
							| 
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 |  |  | import {TestComponentBuilder} from '@angular/compiler/testing'; | 
					
						
							| 
									
										
										
											
												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
										 |  |  | import {expect} from '@angular/platform-browser/testing/matchers'; | 
					
						
							| 
									
										
										
										
											2016-05-20 16:11:49 -07:00
										 |  |  | import {Injectable, provide, Component, ViewMetadata} from '@angular/core'; | 
					
						
							| 
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 |  |  | import {NgIf} from '@angular/common'; | 
					
						
							|  |  |  | import {PromiseWrapper} from '../../http/src/facade/promise'; | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Services, and components for the tests.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 13:36:48 -08:00
										 |  |  | @Component( | 
					
						
							|  |  |  |     {selector: 'child-comp', template: `<span>Original {{childBinding}}</span>`, directives: []}) | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | @Injectable() | 
					
						
							|  |  |  | class ChildComp { | 
					
						
							|  |  |  |   childBinding: string; | 
					
						
							|  |  |  |   constructor() { this.childBinding = 'Child'; } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 13:36:48 -08:00
										 |  |  | @Component({selector: 'child-comp', template: `<span>Mock</span>`}) | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | @Injectable() | 
					
						
							|  |  |  | class MockChildComp { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 13:36:48 -08:00
										 |  |  | @Component({ | 
					
						
							|  |  |  |   selector: 'parent-comp', | 
					
						
							|  |  |  |   template: `Parent(<child-comp></child-comp>)`, | 
					
						
							|  |  |  |   directives: [ChildComp] | 
					
						
							|  |  |  | }) | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | @Injectable() | 
					
						
							|  |  |  | class ParentComp { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 13:36:48 -08:00
										 |  |  | @Component({ | 
					
						
							|  |  |  |   selector: 'my-if-comp', | 
					
						
							|  |  |  |   template: `MyIf(<span *ngIf="showMore">More</span>)`, | 
					
						
							|  |  |  |   directives: [NgIf] | 
					
						
							|  |  |  | }) | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | @Injectable() | 
					
						
							|  |  |  | class MyIfComp { | 
					
						
							|  |  |  |   showMore: boolean = false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 13:36:48 -08:00
										 |  |  | @Component({selector: 'child-child-comp', template: `<span>ChildChild</span>`}) | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | @Injectable() | 
					
						
							|  |  |  | class ChildChildComp { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 13:36:48 -08:00
										 |  |  | @Component({ | 
					
						
							|  |  |  |   selector: 'child-comp', | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |   template: `<span>Original {{childBinding}}(<child-child-comp></child-child-comp>)</span>`, | 
					
						
							|  |  |  |   directives: [ChildChildComp] | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | @Injectable() | 
					
						
							|  |  |  | class ChildWithChildComp { | 
					
						
							|  |  |  |   childBinding: string; | 
					
						
							|  |  |  |   constructor() { this.childBinding = 'Child'; } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 13:36:48 -08:00
										 |  |  | @Component({selector: 'child-child-comp', template: `<span>ChildChild Mock</span>`}) | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | @Injectable() | 
					
						
							|  |  |  | class MockChildChildComp { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class FancyService { | 
					
						
							|  |  |  |   value: string = 'real value'; | 
					
						
							|  |  |  |   getAsyncValue() { return Promise.resolve('async value'); } | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |   getTimeoutValue() { | 
					
						
							|  |  |  |     return new Promise((resolve, reject) => { setTimeout(() => {resolve('timeout value')}, 10); }) | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class MockFancyService extends FancyService { | 
					
						
							|  |  |  |   value: string = 'mocked out value'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 13:36:48 -08:00
										 |  |  | @Component({ | 
					
						
							|  |  |  |   selector: 'my-service-comp', | 
					
						
							|  |  |  |   providers: [FancyService], | 
					
						
							|  |  |  |   template: `injected value: {{fancyService.value}}` | 
					
						
							|  |  |  | }) | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | class TestProvidersComp { | 
					
						
							|  |  |  |   constructor(private fancyService: FancyService) {} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 13:36:48 -08:00
										 |  |  | @Component({ | 
					
						
							|  |  |  |   selector: 'my-service-comp', | 
					
						
							|  |  |  |   viewProviders: [FancyService], | 
					
						
							|  |  |  |   template: `injected value: {{fancyService.value}}` | 
					
						
							|  |  |  | }) | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | class TestViewProvidersComp { | 
					
						
							|  |  |  |   constructor(private fancyService: FancyService) {} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |   describe('using the async helper', () => { | 
					
						
							|  |  |  |     var actuallyDone: boolean; | 
					
						
							| 
									
										
										
										
											2015-11-17 12:37:39 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |     beforeEach(() => { actuallyDone = false; }); | 
					
						
							| 
									
										
										
										
											2015-11-17 12:37:39 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |     afterEach(() => { expect(actuallyDone).toEqual(true); }); | 
					
						
							| 
									
										
										
										
											2015-11-17 12:37:39 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |     it('should run normal tests', () => { actuallyDone = true; }); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 15:45:15 -07:00
										 |  |  |     it('should run normal async tests', (done: any /** TODO #9100 */) => { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |       setTimeout(() => { | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |         actuallyDone = true; | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |         done(); | 
					
						
							|  |  |  |       }, 0); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |     it('should run async tests with tasks', | 
					
						
							|  |  |  |        async(() => { setTimeout(() => { actuallyDone = true; }, 0); })); | 
					
						
							| 
									
										
										
										
											2015-10-14 09:41:15 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |     it('should run async tests with promises', async(() => { | 
					
						
							|  |  |  |          var p = new Promise((resolve, reject) => { setTimeout(resolve, 10); }); | 
					
						
							|  |  |  |          p.then(() => { actuallyDone = true; }); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('using the test injector with the inject helper', () => { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |     describe('setting up Providers', () => { | 
					
						
							| 
									
										
										
											
												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
										 |  |  |       beforeEach(() => addProviders([{provide: FancyService, useValue: new FancyService()}])); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |       it('should use set up providers', inject([FancyService], (service: any /** TODO #9100 */) => { | 
					
						
							|  |  |  |            expect(service.value).toEqual('real value'); | 
					
						
							|  |  |  |          })); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |       it('should wait until returned promises', | 
					
						
							|  |  |  |          async(inject([FancyService], (service: any /** TODO #9100 */) => { | 
					
						
							|  |  |  |            service.getAsyncValue().then( | 
					
						
							|  |  |  |                (value: any /** TODO #9100 */) => { expect(value).toEqual('async value'); }); | 
					
						
							|  |  |  |            service.getTimeoutValue().then( | 
					
						
							|  |  |  |                (value: any /** TODO #9100 */) => { expect(value).toEqual('timeout value'); }); | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |          }))); | 
					
						
							| 
									
										
										
										
											2015-12-14 18:51:37 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |       it('should allow the use of fakeAsync', | 
					
						
							|  |  |  |          fakeAsync(inject([FancyService], (service: any /** TODO #9100 */) => { | 
					
						
							| 
									
										
										
										
											2016-06-08 15:45:15 -07:00
										 |  |  |            var value: any /** TODO #9100 */; | 
					
						
							|  |  |  |            service.getAsyncValue().then(function(val: any /** TODO #9100 */) { value = val; }); | 
					
						
							| 
									
										
										
										
											2016-04-18 16:04:35 -07:00
										 |  |  |            tick(); | 
					
						
							|  |  |  |            expect(value).toEqual('async value'); | 
					
						
							|  |  |  |          }))); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 15:45:15 -07:00
										 |  |  |       it('should allow use of "done"', (done: any /** TODO #9100 */) => { | 
					
						
							|  |  |  |         inject([FancyService], (service: any /** TODO #9100 */) => { | 
					
						
							| 
									
										
										
										
											2016-04-26 13:06:50 -07:00
										 |  |  |           let count = 0; | 
					
						
							|  |  |  |           let id = setInterval(() => { | 
					
						
							|  |  |  |             count++; | 
					
						
							|  |  |  |             if (count > 2) { | 
					
						
							|  |  |  |               clearInterval(id); | 
					
						
							|  |  |  |               done(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           }, 5); | 
					
						
							|  |  |  |         })();  // inject needs to be invoked explicitly with ().
 | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |       describe('using beforeEach', () => { | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |         beforeEach(inject([FancyService], (service: any /** TODO #9100 */) => { | 
					
						
							|  |  |  |           service.value = 'value modified in beforeEach'; | 
					
						
							|  |  |  |         })); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |         it('should use modified providers', | 
					
						
							|  |  |  |            inject([FancyService], (service: any /** TODO #9100 */) => { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |              expect(service.value).toEqual('value modified in beforeEach'); | 
					
						
							|  |  |  |            })); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       describe('using async beforeEach', () => { | 
					
						
							| 
									
										
										
										
											2016-06-08 15:45:15 -07:00
										 |  |  |         beforeEach(async(inject([FancyService], (service: any /** TODO #9100 */) => { | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |           service.getAsyncValue().then( | 
					
						
							|  |  |  |               (value: any /** TODO #9100 */) => { service.value = value; }); | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |         }))); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         it('should use asynchronously modified value', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |            inject([FancyService], (service: any /** TODO #9100 */) => { | 
					
						
							|  |  |  |              expect(service.value).toEqual('async value'); | 
					
						
							|  |  |  |            })); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-12-10 12:00:48 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     describe('per test providers', () => { | 
					
						
							|  |  |  |       it('should allow per test providers', | 
					
						
							| 
									
										
										
										
											2016-06-02 17:30:40 -07:00
										 |  |  |          withProviders(() => [{provide: FancyService, useValue: new FancyService()}]) | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |              .inject([FancyService], (service: any /** TODO #9100 */) => { | 
					
						
							|  |  |  |                expect(service.value).toEqual('real value'); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2016-04-26 13:06:50 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should return value from inject', () => { | 
					
						
							| 
									
										
										
										
											2016-06-02 17:30:40 -07:00
										 |  |  |         let retval = withProviders(() => [{provide: FancyService, useValue: new FancyService()}]) | 
					
						
							| 
									
										
										
										
											2016-06-08 15:45:15 -07:00
										 |  |  |                          .inject([FancyService], (service: any /** TODO #9100 */) => { | 
					
						
							| 
									
										
										
										
											2016-04-26 13:06:50 -07:00
										 |  |  |                            expect(service.value).toEqual('real value'); | 
					
						
							|  |  |  |                            return 10; | 
					
						
							|  |  |  |                          })(); | 
					
						
							|  |  |  |         expect(retval).toBe(10); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2015-12-10 12:00:48 -08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('errors', () => { | 
					
						
							|  |  |  |     var originalJasmineIt: any; | 
					
						
							|  |  |  |     var originalJasmineBeforeEach: any; | 
					
						
							| 
									
										
										
										
											2015-11-18 18:46:24 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |     var patchJasmineIt = () => { | 
					
						
							| 
									
										
										
										
											2015-11-18 18:46:24 -08:00
										 |  |  |       var deferred = PromiseWrapper.completer(); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |       originalJasmineIt = jasmine.getEnv().it; | 
					
						
							| 
									
										
										
										
											2016-06-08 15:45:15 -07:00
										 |  |  |       jasmine.getEnv().it = (description: string, fn: any /** TODO #9100 */) => { | 
					
						
							| 
									
										
										
										
											2015-11-18 18:46:24 -08:00
										 |  |  |         var done = () => { deferred.resolve() }; | 
					
						
							| 
									
										
										
										
											2016-06-08 15:45:15 -07:00
										 |  |  |         (<any>done).fail = (err: any /** TODO #9100 */) => { deferred.reject(err) }; | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |         fn(done); | 
					
						
							|  |  |  |         return null; | 
					
						
							| 
									
										
										
										
											2015-11-18 18:46:24 -08:00
										 |  |  |       }; | 
					
						
							|  |  |  |       return deferred.promise; | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     var restoreJasmineIt = () => { jasmine.getEnv().it = originalJasmineIt; }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     var patchJasmineBeforeEach = () => { | 
					
						
							| 
									
										
										
										
											2015-12-08 16:44:04 -08:00
										 |  |  |       var deferred = PromiseWrapper.completer(); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |       originalJasmineBeforeEach = jasmine.getEnv().beforeEach; | 
					
						
							|  |  |  |       jasmine.getEnv().beforeEach = (fn: any) => { | 
					
						
							| 
									
										
										
										
											2015-12-08 16:44:04 -08:00
										 |  |  |         var done = () => { deferred.resolve() }; | 
					
						
							| 
									
										
										
										
											2016-06-08 15:45:15 -07:00
										 |  |  |         (<any>done).fail = (err: any /** TODO #9100 */) => { deferred.reject(err) }; | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |         fn(done); | 
					
						
							|  |  |  |         return null; | 
					
						
							| 
									
										
										
										
											2015-12-08 16:44:04 -08:00
										 |  |  |       }; | 
					
						
							|  |  |  |       return deferred.promise; | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     var restoreJasmineBeforeEach = | 
					
						
							| 
									
										
										
										
											2016-05-20 16:11:49 -07:00
										 |  |  |         () => { jasmine.getEnv().beforeEach = originalJasmineBeforeEach; }; | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 15:45:15 -07:00
										 |  |  |     it('should fail when an asynchronous error is thrown', (done: any /** TODO #9100 */) => { | 
					
						
							| 
									
										
										
										
											2015-11-18 18:46:24 -08:00
										 |  |  |       var itPromise = patchJasmineIt(); | 
					
						
							| 
									
										
										
										
											2016-06-20 17:54:12 -07:00
										 |  |  |       var barError = new Error('bar'); | 
					
						
							| 
									
										
										
										
											2015-11-18 18:46:24 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('throws an async error', | 
					
						
							| 
									
										
										
										
											2016-06-20 17:54:12 -07:00
										 |  |  |          async(inject([], () => { setTimeout(() => { throw barError; }, 0); }))); | 
					
						
							| 
									
										
										
										
											2015-11-18 18:46:24 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |       itPromise.then( | 
					
						
							|  |  |  |           () => { done.fail('Expected test to fail, but it did not'); }, | 
					
						
							|  |  |  |           (err) => { | 
					
						
							| 
									
										
										
										
											2016-06-20 17:54:12 -07:00
										 |  |  |             expect(err).toEqual(barError); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |             done(); | 
					
						
							|  |  |  |           }); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |       restoreJasmineIt(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 15:45:15 -07:00
										 |  |  |     it('should fail when a returned promise is rejected', (done: any /** TODO #9100 */) => { | 
					
						
							| 
									
										
										
										
											2015-11-18 18:46:24 -08:00
										 |  |  |       var itPromise = patchJasmineIt(); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |       it('should fail with an error from a promise', async(inject([], () => { | 
					
						
							| 
									
										
										
										
											2015-11-18 18:46:24 -08:00
										 |  |  |            var deferred = PromiseWrapper.completer(); | 
					
						
							|  |  |  |            var p = deferred.promise.then(() => { expect(1).toEqual(2); }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            deferred.reject('baz'); | 
					
						
							|  |  |  |            return p; | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |          }))); | 
					
						
							| 
									
										
										
										
											2015-11-18 18:46:24 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |       itPromise.then( | 
					
						
							|  |  |  |           () => { done.fail('Expected test to fail, but it did not'); }, | 
					
						
							|  |  |  |           (err) => { | 
					
						
							| 
									
										
										
										
											2016-06-20 17:54:12 -07:00
										 |  |  |             expect(err.message).toEqual('Uncaught (in promise): baz'); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |             done(); | 
					
						
							|  |  |  |           }); | 
					
						
							| 
									
										
										
										
											2015-11-18 18:46:24 -08:00
										 |  |  |       restoreJasmineIt(); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -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
										 |  |  |     describe('using addProviders', () => { | 
					
						
							|  |  |  |       beforeEach(() => addProviders([{provide: FancyService, useValue: new FancyService()}])); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |       beforeEach(inject([FancyService], (service: any /** TODO #9100 */) => { | 
					
						
							|  |  |  |         expect(service.value).toEqual('real value'); | 
					
						
							|  |  |  |       })); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -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
										 |  |  |       describe('nested addProviders', () => { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         it('should fail when the injector has already been used', () => { | 
					
						
							| 
									
										
										
										
											2015-12-08 16:44:04 -08:00
										 |  |  |           patchJasmineBeforeEach(); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |           expect(() => { | 
					
						
							| 
									
										
										
											
												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
										 |  |  |             beforeEach(() => addProviders([{provide: FancyService, useValue: new FancyService()}])); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |           }) | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |               .toThrowError( | 
					
						
							| 
									
										
										
											
												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
										 |  |  |                   'addProviders can\'t be called after the injector has been already created for this test. ' + | 
					
						
							|  |  |  |                   'This is most likely because you\'ve already used the injector to inject a beforeEach or the ' + | 
					
						
							|  |  |  |                   'current `it` function.'); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |           restoreJasmineBeforeEach(); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('test component builder', function() { | 
					
						
							|  |  |  |     it('should instantiate a component with valid DOM', | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |        async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |          tcb.createAsync(ChildComp).then((componentFixture) => { | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |            componentFixture.detectChanges(); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |            expect(componentFixture.debugElement.nativeElement).toHaveText('Original Child'); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |          }); | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |        }))); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should allow changing members of the component', | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |        async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |          tcb.createAsync(MyIfComp).then((componentFixture) => { | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |            componentFixture.detectChanges(); | 
					
						
							|  |  |  |            expect(componentFixture.debugElement.nativeElement).toHaveText('MyIf()'); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |            componentFixture.debugElement.componentInstance.showMore = true; | 
					
						
							|  |  |  |            componentFixture.detectChanges(); | 
					
						
							|  |  |  |            expect(componentFixture.debugElement.nativeElement).toHaveText('MyIf(More)'); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |          }); | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |        }))); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-08 16:44:04 -08:00
										 |  |  |     it('should override a template', | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |        async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |          tcb.overrideTemplate(MockChildComp, '<span>Mock</span>') | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |              .createAsync(MockChildComp) | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |              .then((componentFixture) => { | 
					
						
							|  |  |  |                componentFixture.detectChanges(); | 
					
						
							|  |  |  |                expect(componentFixture.debugElement.nativeElement).toHaveText('Mock'); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |              }); | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |        }))); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-08 16:44:04 -08:00
										 |  |  |     it('should override a view', | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |        async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          tcb.overrideView( | 
					
						
							|  |  |  |                 ChildComp, new ViewMetadata({template: '<span>Modified {{childBinding}}</span>'})) | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |              .createAsync(ChildComp) | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |              .then((componentFixture) => { | 
					
						
							|  |  |  |                componentFixture.detectChanges(); | 
					
						
							|  |  |  |                expect(componentFixture.debugElement.nativeElement).toHaveText('Modified Child'); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |              }); | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |        }))); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should override component dependencies', | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |        async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |          tcb.overrideDirective(ParentComp, ChildComp, MockChildComp) | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |              .createAsync(ParentComp) | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |              .then((componentFixture) => { | 
					
						
							|  |  |  |                componentFixture.detectChanges(); | 
					
						
							|  |  |  |                expect(componentFixture.debugElement.nativeElement).toHaveText('Parent(Mock)'); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |              }); | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |        }))); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |     it('should override child component\'s dependencies', | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |        async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |          tcb.overrideDirective(ParentComp, ChildComp, ChildWithChildComp) | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |              .overrideDirective(ChildWithChildComp, ChildChildComp, MockChildChildComp) | 
					
						
							|  |  |  |              .createAsync(ParentComp) | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |              .then((componentFixture) => { | 
					
						
							|  |  |  |                componentFixture.detectChanges(); | 
					
						
							|  |  |  |                expect(componentFixture.debugElement.nativeElement) | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |                    .toHaveText('Parent(Original Child(ChildChild Mock))'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |              }); | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |        }))); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-08 16:44:04 -08:00
										 |  |  |     it('should override a provider', | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |        async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          tcb.overrideProviders( | 
					
						
							|  |  |  |                 TestProvidersComp, [{provide: FancyService, useClass: MockFancyService}]) | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |              .createAsync(TestProvidersComp) | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |              .then((componentFixture) => { | 
					
						
							|  |  |  |                componentFixture.detectChanges(); | 
					
						
							|  |  |  |                expect(componentFixture.debugElement.nativeElement) | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |                    .toHaveText('injected value: mocked out value'); | 
					
						
							|  |  |  |              }); | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |        }))); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should override a viewProvider', | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |        async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |          tcb.overrideViewProviders( | 
					
						
							|  |  |  |                 TestViewProvidersComp, [{provide: FancyService, useClass: MockFancyService}]) | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |              .createAsync(TestViewProvidersComp) | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |              .then((componentFixture) => { | 
					
						
							|  |  |  |                componentFixture.detectChanges(); | 
					
						
							|  |  |  |                expect(componentFixture.debugElement.nativeElement) | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |                    .toHaveText('injected value: mocked out value'); | 
					
						
							|  |  |  |              }); | 
					
						
							| 
									
										
											  
											
												feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
  return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
  return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
  service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
  somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
											
										 
											2016-03-23 10:59:38 -07:00
										 |  |  |        }))); | 
					
						
							| 
									
										
										
										
											2015-10-08 15:33:17 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | } |