| 
									
										
										
										
											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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 |  |  | import {NgIf} from '@angular/common'; | 
					
						
							| 
									
										
										
										
											2016-08-02 15:53:34 -07:00
										 |  |  | import {Component, Injectable, Input, NgModule, Pipe, ViewMetadata} from '@angular/core'; | 
					
						
							|  |  |  | import {ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, TestComponentBuilder, withProviders} from '@angular/core/testing'; | 
					
						
							|  |  |  | import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; | 
					
						
							| 
									
										
										
										
											2016-06-23 16:42:25 -07:00
										 |  |  | import {dispatchEvent} from '@angular/platform-browser/testing/browser_util'; | 
					
						
							| 
									
										
										
										
											2016-08-02 15:53:34 -07:00
										 |  |  | import {expect} from '@angular/platform-browser/testing/matchers'; | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | @Component( | 
					
						
							|  |  |  |     {selector: 'child-comp', template: `<span>Original {{childBinding}}</span>`, directives: []}) | 
					
						
							|  |  |  | @Injectable() | 
					
						
							|  |  |  | class ChildComp { | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  |   childBinding: string; | 
					
						
							| 
									
										
										
										
											2015-05-28 15:02:20 -07:00
										 |  |  |   constructor() { this.childBinding = 'Child'; } | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 13:36:48 -08:00
										 |  |  | @Component({selector: 'child-comp', template: `<span>Mock</span>`}) | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -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-05-15 16:42:52 -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-05-15 16:42:52 -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-08-17 11:43:14 -07:00
										 |  |  | @Injectable() | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  | class ChildChildComp { | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-08-17 11:43:14 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 13:36:48 -08:00
										 |  |  | @Component({ | 
					
						
							|  |  |  |   selector: 'child-comp', | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  |   template: `<span>Original {{childBinding}}(<child-child-comp></child-child-comp>)</span>`, | 
					
						
							|  |  |  |   directives: [ChildChildComp] | 
					
						
							|  |  |  | }) | 
					
						
							| 
									
										
										
										
											2015-08-17 11:43:14 -07:00
										 |  |  | @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-08-17 11:43:14 -07:00
										 |  |  | @Injectable() | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  | class MockChildChildComp { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-26 16:38:54 -07:00
										 |  |  | @Component({selector: 'autodetect-comp', template: `<span (click)='click()'>{{text}}</span>`}) | 
					
						
							|  |  |  | class AutoDetectComp { | 
					
						
							|  |  |  |   text: string = '1'; | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-26 16:38:54 -07:00
										 |  |  |   click() { this.text += '1'; } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component({selector: 'async-comp', template: `<span (click)='click()'>{{text}}</span>`}) | 
					
						
							|  |  |  | class AsyncComp { | 
					
						
							|  |  |  |   text: string = '1'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   click() { | 
					
						
							| 
									
										
										
										
											2016-08-02 15:53:34 -07:00
										 |  |  |     Promise.resolve(null).then((_) => { this.text += '1'; }); | 
					
						
							| 
									
										
										
										
											2016-04-26 16:38:54 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component({selector: 'async-child-comp', template: '<span>{{localText}}</span>'}) | 
					
						
							|  |  |  | class AsyncChildComp { | 
					
						
							|  |  |  |   localText: string = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @Input() | 
					
						
							|  |  |  |   set text(value: string) { | 
					
						
							| 
									
										
										
										
											2016-08-02 15:53:34 -07:00
										 |  |  |     Promise.resolve(null).then((_) => { this.localText = value; }); | 
					
						
							| 
									
										
										
										
											2016-04-26 16:38:54 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component({ | 
					
						
							|  |  |  |   selector: 'async-change-comp', | 
					
						
							|  |  |  |   template: `<async-child-comp (click)='click()' [text]="text"></async-child-comp>`, | 
					
						
							|  |  |  |   directives: [AsyncChildComp] | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | class AsyncChangeComp { | 
					
						
							|  |  |  |   text: string = '1'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   click() { this.text += '1'; } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 11:26:07 -07:00
										 |  |  | @Component({selector: 'async-timeout-comp', template: `<span (click)='click()'>{{text}}</span>`}) | 
					
						
							|  |  |  | class AsyncTimeoutComp { | 
					
						
							|  |  |  |   text: string = '1'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   click() { | 
					
						
							| 
									
										
										
										
											2016-08-02 15:53:34 -07:00
										 |  |  |     setTimeout(() => { this.text += '1'; }, 10); | 
					
						
							| 
									
										
										
										
											2016-05-03 11:26:07 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component( | 
					
						
							|  |  |  |     {selector: 'nested-async-timeout-comp', template: `<span (click)='click()'>{{text}}</span>`}) | 
					
						
							|  |  |  | class NestedAsyncTimeoutComp { | 
					
						
							|  |  |  |   text: string = '1'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   click() { | 
					
						
							| 
									
										
										
										
											2016-08-02 15:53:34 -07:00
										 |  |  |     setTimeout(() => { setTimeout(() => { this.text += '1'; }, 10); }, 10); | 
					
						
							| 
									
										
										
										
											2016-05-03 11:26:07 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  | class FancyService { | 
					
						
							|  |  |  |   value: string = 'real value'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class MockFancyService extends FancyService { | 
					
						
							|  |  |  |   value: string = 'mocked out value'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-08 13:36:48 -08:00
										 |  |  | @Component({ | 
					
						
							|  |  |  |   selector: 'my-service-comp', | 
					
						
							| 
									
										
										
										
											2016-03-21 16:27:17 +05:30
										 |  |  |   providers: [FancyService], | 
					
						
							| 
									
										
										
										
											2016-03-08 13:36:48 -08:00
										 |  |  |   template: `injected value: {{fancyService.value}}` | 
					
						
							|  |  |  | }) | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  | class TestBindingsComp { | 
					
						
							|  |  |  |   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-09-08 10:14:57 -07:00
										 |  |  | class TestViewBindingsComp { | 
					
						
							|  |  |  |   constructor(private fancyService: FancyService) {} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-08-17 11:43:14 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-24 23:11:30 -07:00
										 |  |  | @Component({selector: 'li1', template: `<span>One</span>`}) | 
					
						
							|  |  |  | class ListDir1 { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component({selector: 'li1', template: `<span>Alternate One</span>`}) | 
					
						
							|  |  |  | class ListDir1Alt { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component({selector: 'li2', template: `<span>Two</span>`}) | 
					
						
							|  |  |  | class ListDir2 { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-30 19:18:14 -07:00
										 |  |  | const LIST_CHILDREN = [ListDir1, ListDir2]; | 
					
						
							| 
									
										
										
										
											2016-04-24 23:11:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | @Component({ | 
					
						
							|  |  |  |   selector: 'directive-list-comp', | 
					
						
							|  |  |  |   template: `(<li1></li1>)(<li2></li2>)`, | 
					
						
							|  |  |  |   directives: [LIST_CHILDREN] | 
					
						
							|  |  |  | }) | 
					
						
							| 
									
										
										
										
											2016-04-24 23:11:30 -07:00
										 |  |  | class DirectiveListComp { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-17 11:43:14 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | export function main() { | 
					
						
							|  |  |  |   describe('test component builder', function() { | 
					
						
							|  |  |  |     it('should instantiate a component with valid DOM', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |        inject( | 
					
						
							|  |  |  |            [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |            (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |              tcb.createAsync(ChildComp).then((componentFixture) => { | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |                componentFixture.detectChanges(); | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                expect(componentFixture.nativeElement).toHaveText('Original Child'); | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |            })); | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |     it('should allow changing members of the component', | 
					
						
							|  |  |  |        inject( | 
					
						
							|  |  |  |            [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |            (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |              tcb.createAsync(MyIfComp).then((componentFixture) => { | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |                componentFixture.detectChanges(); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                expect(componentFixture.nativeElement).toHaveText('MyIf()'); | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                componentFixture.componentInstance.showMore = true; | 
					
						
							| 
									
										
										
										
											2015-10-31 09:50:19 -07:00
										 |  |  |                componentFixture.detectChanges(); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                expect(componentFixture.nativeElement).toHaveText('MyIf(More)'); | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |                async.done(); | 
					
						
							|  |  |  |              }); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |            })); | 
					
						
							| 
									
										
										
										
											2015-08-17 11:43:14 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |     it('should override a template', | 
					
						
							|  |  |  |        inject( | 
					
						
							|  |  |  |            [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |            (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2016-04-24 23:11:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |              tcb.overrideTemplate(MockChildComp, '<span>Mock</span>') | 
					
						
							|  |  |  |                  .createAsync(MockChildComp) | 
					
						
							|  |  |  |                  .then((componentFixture) => { | 
					
						
							|  |  |  |                    componentFixture.detectChanges(); | 
					
						
							|  |  |  |                    expect(componentFixture.nativeElement).toHaveText('Mock'); | 
					
						
							| 
									
										
										
										
											2016-04-24 23:11:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							| 
									
										
										
										
											2015-08-17 11:43:14 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |     it('should override a view', | 
					
						
							|  |  |  |        inject( | 
					
						
							|  |  |  |            [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |            (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |              tcb.overrideView( | 
					
						
							|  |  |  |                     ChildComp, | 
					
						
							|  |  |  |                     new ViewMetadata({template: '<span>Modified {{childBinding}}</span>'})) | 
					
						
							|  |  |  |                  .createAsync(ChildComp) | 
					
						
							|  |  |  |                  .then((componentFixture) => { | 
					
						
							|  |  |  |                    componentFixture.detectChanges(); | 
					
						
							|  |  |  |                    expect(componentFixture.nativeElement).toHaveText('Modified Child'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |     it('should override component dependencies', | 
					
						
							|  |  |  |        inject( | 
					
						
							|  |  |  |            [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |            (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |              tcb.overrideDirective(ParentComp, ChildComp, MockChildComp) | 
					
						
							|  |  |  |                  .createAsync(ParentComp) | 
					
						
							|  |  |  |                  .then((componentFixture) => { | 
					
						
							|  |  |  |                    componentFixture.detectChanges(); | 
					
						
							|  |  |  |                    expect(componentFixture.nativeElement).toHaveText('Parent(Mock)'); | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |     it('should override items from a list', | 
					
						
							|  |  |  |        inject( | 
					
						
							|  |  |  |            [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |            (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |              tcb.overrideDirective(DirectiveListComp, ListDir1, ListDir1Alt) | 
					
						
							|  |  |  |                  .createAsync(DirectiveListComp) | 
					
						
							|  |  |  |                  .then((componentFixture) => { | 
					
						
							|  |  |  |                    componentFixture.detectChanges(); | 
					
						
							|  |  |  |                    expect(componentFixture.nativeElement).toHaveText('(Alternate One)(Two)'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should override child component\'s dependencies', | 
					
						
							|  |  |  |        inject( | 
					
						
							|  |  |  |            [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |            (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |              tcb.overrideDirective(ParentComp, ChildComp, ChildWithChildComp) | 
					
						
							|  |  |  |                  .overrideDirective(ChildWithChildComp, ChildChildComp, MockChildChildComp) | 
					
						
							|  |  |  |                  .createAsync(ParentComp) | 
					
						
							|  |  |  |                  .then((componentFixture) => { | 
					
						
							|  |  |  |                    componentFixture.detectChanges(); | 
					
						
							|  |  |  |                    expect(componentFixture.nativeElement) | 
					
						
							|  |  |  |                        .toHaveText('Parent(Original Child(ChildChild Mock))'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |     it('should override a provider', | 
					
						
							|  |  |  |        inject( | 
					
						
							|  |  |  |            [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |            (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |              tcb.overrideProviders( | 
					
						
							|  |  |  |                     TestBindingsComp, [{provide: FancyService, useClass: MockFancyService}]) | 
					
						
							|  |  |  |                  .createAsync(TestBindingsComp) | 
					
						
							|  |  |  |                  .then((componentFixture) => { | 
					
						
							|  |  |  |                    componentFixture.detectChanges(); | 
					
						
							|  |  |  |                    expect(componentFixture.nativeElement) | 
					
						
							|  |  |  |                        .toHaveText('injected value: mocked out value'); | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							| 
									
										
										
										
											2015-09-08 10:14:57 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |     it('should override a viewBinding', | 
					
						
							|  |  |  |        inject( | 
					
						
							|  |  |  |            [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |            (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |              tcb.overrideViewProviders( | 
					
						
							|  |  |  |                     TestViewBindingsComp, [{provide: FancyService, useClass: MockFancyService}]) | 
					
						
							|  |  |  |                  .createAsync(TestViewBindingsComp) | 
					
						
							|  |  |  |                  .then((componentFixture) => { | 
					
						
							|  |  |  |                    componentFixture.detectChanges(); | 
					
						
							|  |  |  |                    expect(componentFixture.nativeElement) | 
					
						
							|  |  |  |                        .toHaveText('injected value: mocked out value'); | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |            })); | 
					
						
							| 
									
										
										
										
											2016-04-26 16:38:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 08:46:43 -07:00
										 |  |  |     it('should create components synchronously', | 
					
						
							|  |  |  |        inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          let componentFixture = | 
					
						
							|  |  |  |              tcb.overrideTemplate(MockChildComp, '<span>Mock</span>').createSync(MockChildComp); | 
					
						
							|  |  |  |          componentFixture.detectChanges(); | 
					
						
							|  |  |  |          expect(componentFixture.nativeElement).toHaveText('Mock'); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |     describe('ComponentFixture', () => { | 
					
						
							|  |  |  |       it('should auto detect changes if autoDetectChanges is called', | 
					
						
							|  |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                tcb.createAsync(AutoDetectComp).then((componentFixture) => { | 
					
						
							|  |  |  |                  expect(componentFixture.ngZone).not.toBeNull(); | 
					
						
							|  |  |  |                  componentFixture.autoDetectChanges(); | 
					
						
							|  |  |  |                  expect(componentFixture.nativeElement).toHaveText('1'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  let element = componentFixture.debugElement.children[0]; | 
					
						
							|  |  |  |                  dispatchEvent(element.nativeElement, 'click'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  expect(componentFixture.isStable()).toBe(true); | 
					
						
							|  |  |  |                  expect(componentFixture.nativeElement).toHaveText('11'); | 
					
						
							|  |  |  |                  async.done(); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |              })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should auto detect changes if ComponentFixtureAutoDetect is provided as true', | 
					
						
							|  |  |  |          withProviders(() => [{provide: ComponentFixtureAutoDetect, useValue: true}]) | 
					
						
							|  |  |  |              .inject( | 
					
						
							|  |  |  |                  [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |                  (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |                    tcb.createAsync(AutoDetectComp).then((componentFixture) => { | 
					
						
							|  |  |  |                      expect(componentFixture.nativeElement).toHaveText('1'); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |                      let element = componentFixture.debugElement.children[0]; | 
					
						
							|  |  |  |                      dispatchEvent(element.nativeElement, 'click'); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |                      expect(componentFixture.nativeElement).toHaveText('11'); | 
					
						
							|  |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |                  })); | 
					
						
							| 
									
										
										
										
											2016-04-26 16:38:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |       it('should signal through whenStable when the fixture is stable (autoDetectChanges)', | 
					
						
							|  |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |                tcb.createAsync(AsyncComp).then((componentFixture) => { | 
					
						
							|  |  |  |                  componentFixture.autoDetectChanges(); | 
					
						
							|  |  |  |                  expect(componentFixture.nativeElement).toHaveText('1'); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |                  let element = componentFixture.debugElement.children[0]; | 
					
						
							|  |  |  |                  dispatchEvent(element.nativeElement, 'click'); | 
					
						
							|  |  |  |                  expect(componentFixture.nativeElement).toHaveText('1'); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |                  // Component is updated asynchronously. Wait for the fixture to become stable
 | 
					
						
							|  |  |  |                  // before checking for new value.
 | 
					
						
							|  |  |  |                  expect(componentFixture.isStable()).toBe(false); | 
					
						
							|  |  |  |                  componentFixture.whenStable().then((waited) => { | 
					
						
							|  |  |  |                    expect(waited).toBe(true); | 
					
						
							|  |  |  |                    expect(componentFixture.nativeElement).toHaveText('11'); | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                  }); | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |                }); | 
					
						
							|  |  |  |              })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should signal through isStable when the fixture is stable (no autoDetectChanges)', | 
					
						
							|  |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                tcb.createAsync(AsyncComp).then((componentFixture) => { | 
					
						
							|  |  |  |                  componentFixture.detectChanges(); | 
					
						
							|  |  |  |                  expect(componentFixture.nativeElement).toHaveText('1'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  let element = componentFixture.debugElement.children[0]; | 
					
						
							|  |  |  |                  dispatchEvent(element.nativeElement, 'click'); | 
					
						
							|  |  |  |                  expect(componentFixture.nativeElement).toHaveText('1'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  // Component is updated asynchronously. Wait for the fixture to become stable
 | 
					
						
							|  |  |  |                  // before checking.
 | 
					
						
							|  |  |  |                  componentFixture.whenStable().then((waited) => { | 
					
						
							|  |  |  |                    expect(waited).toBe(true); | 
					
						
							|  |  |  |                    componentFixture.detectChanges(); | 
					
						
							|  |  |  |                    expect(componentFixture.nativeElement).toHaveText('11'); | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                  }); | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |                }); | 
					
						
							|  |  |  |              })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should wait for macroTask(setTimeout) while checking for whenStable ' + | 
					
						
							|  |  |  |              '(autoDetectChanges)', | 
					
						
							|  |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                tcb.createAsync(AsyncTimeoutComp).then((componentFixture) => { | 
					
						
							|  |  |  |                  componentFixture.autoDetectChanges(); | 
					
						
							|  |  |  |                  expect(componentFixture.nativeElement).toHaveText('1'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  let element = componentFixture.debugElement.children[0]; | 
					
						
							|  |  |  |                  dispatchEvent(element.nativeElement, 'click'); | 
					
						
							|  |  |  |                  expect(componentFixture.nativeElement).toHaveText('1'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  // Component is updated asynchronously. Wait for the fixture to become
 | 
					
						
							|  |  |  |                  // stable before checking for new value.
 | 
					
						
							|  |  |  |                  expect(componentFixture.isStable()).toBe(false); | 
					
						
							|  |  |  |                  componentFixture.whenStable().then((waited) => { | 
					
						
							|  |  |  |                    expect(waited).toBe(true); | 
					
						
							|  |  |  |                    expect(componentFixture.nativeElement).toHaveText('11'); | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |              })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should wait for macroTask(setTimeout) while checking for whenStable ' + | 
					
						
							|  |  |  |              '(no autoDetectChanges)', | 
					
						
							|  |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                tcb.createAsync(AsyncTimeoutComp).then((componentFixture) => { | 
					
						
							|  |  |  |                  componentFixture.detectChanges(); | 
					
						
							|  |  |  |                  expect(componentFixture.nativeElement).toHaveText('1'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  let element = componentFixture.debugElement.children[0]; | 
					
						
							|  |  |  |                  dispatchEvent(element.nativeElement, 'click'); | 
					
						
							|  |  |  |                  expect(componentFixture.nativeElement).toHaveText('1'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  // Component is updated asynchronously. Wait for the fixture to become
 | 
					
						
							|  |  |  |                  // stable before checking for new value.
 | 
					
						
							|  |  |  |                  expect(componentFixture.isStable()).toBe(false); | 
					
						
							|  |  |  |                  componentFixture.whenStable().then((waited) => { | 
					
						
							|  |  |  |                    expect(waited).toBe(true); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                    componentFixture.detectChanges(); | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |                    expect(componentFixture.nativeElement).toHaveText('11'); | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                  }); | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |                }); | 
					
						
							|  |  |  |              })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should wait for nested macroTasks(setTimeout) while checking for whenStable ' + | 
					
						
							|  |  |  |              '(autoDetectChanges)', | 
					
						
							|  |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                tcb.createAsync(NestedAsyncTimeoutComp).then((componentFixture) => { | 
					
						
							|  |  |  |                  componentFixture.autoDetectChanges(); | 
					
						
							|  |  |  |                  expect(componentFixture.nativeElement).toHaveText('1'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  let element = componentFixture.debugElement.children[0]; | 
					
						
							|  |  |  |                  dispatchEvent(element.nativeElement, 'click'); | 
					
						
							|  |  |  |                  expect(componentFixture.nativeElement).toHaveText('1'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  // Component is updated asynchronously. Wait for the fixture to become
 | 
					
						
							|  |  |  |                  // stable before checking for new value.
 | 
					
						
							|  |  |  |                  expect(componentFixture.isStable()).toBe(false); | 
					
						
							|  |  |  |                  componentFixture.whenStable().then((waited) => { | 
					
						
							|  |  |  |                    expect(waited).toBe(true); | 
					
						
							|  |  |  |                    expect(componentFixture.nativeElement).toHaveText('11'); | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |              })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should wait for nested macroTasks(setTimeout) while checking for whenStable ' + | 
					
						
							|  |  |  |              '(no autoDetectChanges)', | 
					
						
							|  |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                tcb.createAsync(NestedAsyncTimeoutComp).then((componentFixture) => { | 
					
						
							|  |  |  |                  componentFixture.detectChanges(); | 
					
						
							|  |  |  |                  expect(componentFixture.nativeElement).toHaveText('1'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  let element = componentFixture.debugElement.children[0]; | 
					
						
							|  |  |  |                  dispatchEvent(element.nativeElement, 'click'); | 
					
						
							|  |  |  |                  expect(componentFixture.nativeElement).toHaveText('1'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                  // Component is updated asynchronously. Wait for the fixture to become
 | 
					
						
							|  |  |  |                  // stable before checking for new value.
 | 
					
						
							|  |  |  |                  expect(componentFixture.isStable()).toBe(false); | 
					
						
							|  |  |  |                  componentFixture.whenStable().then((waited) => { | 
					
						
							|  |  |  |                    expect(waited).toBe(true); | 
					
						
							|  |  |  |                    componentFixture.detectChanges(); | 
					
						
							|  |  |  |                    expect(componentFixture.nativeElement).toHaveText('11'); | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							|  |  |  |                  }); | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  |              })); | 
					
						
							| 
									
										
										
										
											2016-05-03 11:26:07 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |       it('should stabilize after async task in change detection (autoDetectChanges)', | 
					
						
							|  |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |                tcb.createAsync(AsyncChangeComp).then((componentFixture) => { | 
					
						
							|  |  |  |                  componentFixture.autoDetectChanges(); | 
					
						
							|  |  |  |                  componentFixture.whenStable().then((_) => { | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                    expect(componentFixture.nativeElement).toHaveText('1'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                    let element = componentFixture.debugElement.children[0]; | 
					
						
							|  |  |  |                    dispatchEvent(element.nativeElement, 'click'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |                    componentFixture.whenStable().then((_) => { | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      expect(componentFixture.nativeElement).toHaveText('11'); | 
					
						
							|  |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |                  }); | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |                }); | 
					
						
							|  |  |  |              })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should stabilize after async task in change detection(no autoDetectChanges)', | 
					
						
							|  |  |  |          inject( | 
					
						
							|  |  |  |              [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |              (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                tcb.createAsync(AsyncChangeComp).then((componentFixture) => { | 
					
						
							|  |  |  |                  componentFixture.detectChanges(); | 
					
						
							|  |  |  |                  componentFixture.whenStable().then((_) => { | 
					
						
							|  |  |  |                    // Run detectChanges again so that stabilized value is reflected in the
 | 
					
						
							|  |  |  |                    // DOM.
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                    componentFixture.detectChanges(); | 
					
						
							|  |  |  |                    expect(componentFixture.nativeElement).toHaveText('1'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                    let element = componentFixture.debugElement.children[0]; | 
					
						
							|  |  |  |                    dispatchEvent(element.nativeElement, 'click'); | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |                    componentFixture.detectChanges(); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |                    componentFixture.whenStable().then((_) => { | 
					
						
							|  |  |  |                      // Run detectChanges again so that stabilized value is reflected in
 | 
					
						
							|  |  |  |                      // the DOM.
 | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                      componentFixture.detectChanges(); | 
					
						
							|  |  |  |                      expect(componentFixture.nativeElement).toHaveText('11'); | 
					
						
							|  |  |  |                      async.done(); | 
					
						
							|  |  |  |                    }); | 
					
						
							|  |  |  |                  }); | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |                }); | 
					
						
							|  |  |  |              })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       describe('No NgZone', () => { | 
					
						
							|  |  |  |         beforeEachProviders(() => [{provide: ComponentFixtureNoNgZone, useValue: true}]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it('calling autoDetectChanges raises an error', () => { | 
					
						
							|  |  |  |           inject( | 
					
						
							|  |  |  |               [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |               (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  |                 tcb.createAsync(ChildComp).then((componentFixture) => { | 
					
						
							|  |  |  |                   expect(() => { componentFixture.autoDetectChanges(); }) | 
					
						
							|  |  |  |                       .toThrow( | 
					
						
							|  |  |  |                           'Cannot call autoDetectChanges when ComponentFixtureNoNgZone is set!!'); | 
					
						
							|  |  |  |                   async.done(); | 
					
						
							|  |  |  |                 }); | 
					
						
							|  |  |  |               }); | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2016-05-03 11:26:07 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |         it('should instantiate a component with valid DOM', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |            inject( | 
					
						
							|  |  |  |                [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |                (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |                  tcb.createAsync(ChildComp).then((componentFixture) => { | 
					
						
							|  |  |  |                    expect(componentFixture.ngZone).toBeNull(); | 
					
						
							|  |  |  |                    componentFixture.detectChanges(); | 
					
						
							|  |  |  |                    expect(componentFixture.nativeElement).toHaveText('Original Child'); | 
					
						
							|  |  |  |                    async.done(); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                  }); | 
					
						
							|  |  |  |                })); | 
					
						
							| 
									
										
										
										
											2016-04-26 16:38:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |         it('should allow changing members of the component', | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |            inject( | 
					
						
							|  |  |  |                [TestComponentBuilder, AsyncTestCompleter], | 
					
						
							|  |  |  |                (tcb: TestComponentBuilder, async: AsyncTestCompleter) => { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |                  tcb.createAsync(MyIfComp).then((componentFixture) => { | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                    componentFixture.detectChanges(); | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |                    expect(componentFixture.nativeElement).toHaveText('MyIf()'); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |                    componentFixture.componentInstance.showMore = true; | 
					
						
							|  |  |  |                    componentFixture.detectChanges(); | 
					
						
							|  |  |  |                    expect(componentFixture.nativeElement).toHaveText('MyIf(More)'); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |                    async.done(); | 
					
						
							| 
									
										
										
										
											2016-06-08 16:38:52 -07:00
										 |  |  |                  }); | 
					
						
							|  |  |  |                })); | 
					
						
							| 
									
										
										
										
											2016-04-26 16:38:54 -07:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-05-15 16:42:52 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | } |