| 
									
										
										
										
											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 {Component, Directive} from '@angular/core'; | 
					
						
							|  |  |  | import {ElementRef} from '@angular/core/src/linker/element_ref'; | 
					
						
							| 
									
										
										
										
											2016-09-08 20:37:20 -07:00
										 |  |  | import {ComponentFixture, TestBed, async} from '@angular/core/testing'; | 
					
						
							| 
									
										
										
										
											2016-08-02 15:53:34 -07:00
										 |  |  | import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; | 
					
						
							|  |  |  | import {expect} from '@angular/platform-browser/testing/matchers'; | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | export function main() { | 
					
						
							|  |  |  |   describe('non-bindable', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-15 13:52:57 -07:00
										 |  |  |     beforeEach(() => { | 
					
						
							|  |  |  |       TestBed.configureTestingModule({ | 
					
						
							| 
									
										
										
										
											2016-08-19 12:51:01 -07:00
										 |  |  |         declarations: [TestComponent, TestDirective], | 
					
						
							| 
									
										
										
										
											2016-08-15 13:52:57 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-06-24 13:07:15 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-15 13:52:57 -07:00
										 |  |  |     it('should not interpolate children', async(() => { | 
					
						
							| 
									
										
										
										
											2016-09-08 20:37:20 -07:00
										 |  |  |          const template = '<div>{{text}}<span ngNonBindable>{{text}}</span></div>'; | 
					
						
							|  |  |  |          const fixture = createTestComponent(template); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-15 13:52:57 -07:00
										 |  |  |          fixture.detectChanges(); | 
					
						
							| 
									
										
										
										
											2016-09-08 20:37:20 -07:00
										 |  |  |          expect(fixture.nativeElement).toHaveText('foo{{text}}'); | 
					
						
							| 
									
										
										
										
											2016-08-15 13:52:57 -07:00
										 |  |  |        })); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-15 13:52:57 -07:00
										 |  |  |     it('should ignore directives on child nodes', async(() => { | 
					
						
							| 
									
										
										
										
											2016-09-08 20:37:20 -07:00
										 |  |  |          const template = '<div ngNonBindable><span id=child test-dec>{{text}}</span></div>'; | 
					
						
							|  |  |  |          const fixture = createTestComponent(template); | 
					
						
							| 
									
										
										
										
											2016-08-15 13:52:57 -07:00
										 |  |  |          fixture.detectChanges(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          // We must use getDOM().querySelector instead of fixture.query here
 | 
					
						
							|  |  |  |          // since the elements inside are not compiled.
 | 
					
						
							| 
									
										
										
										
											2016-09-08 20:37:20 -07:00
										 |  |  |          const span = getDOM().querySelector(fixture.nativeElement, '#child'); | 
					
						
							| 
									
										
										
										
											2016-08-15 13:52:57 -07:00
										 |  |  |          expect(getDOM().hasClass(span, 'compiled')).toBeFalsy(); | 
					
						
							|  |  |  |        })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should trigger directives on the same node', async(() => { | 
					
						
							| 
									
										
										
										
											2016-09-08 20:37:20 -07:00
										 |  |  |          const template = '<div><span id=child ngNonBindable test-dec>{{text}}</span></div>'; | 
					
						
							|  |  |  |          const fixture = createTestComponent(template); | 
					
						
							| 
									
										
										
										
											2016-08-15 13:52:57 -07:00
										 |  |  |          fixture.detectChanges(); | 
					
						
							| 
									
										
										
										
											2016-09-08 20:37:20 -07:00
										 |  |  |          const span = getDOM().querySelector(fixture.nativeElement, '#child'); | 
					
						
							| 
									
										
										
										
											2016-08-15 13:52:57 -07:00
										 |  |  |          expect(getDOM().hasClass(span, 'compiled')).toBeTruthy(); | 
					
						
							|  |  |  |        })); | 
					
						
							| 
									
										
										
										
											2016-07-21 17:12:00 -07:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Directive({selector: '[test-dec]'}) | 
					
						
							|  |  |  | class TestDirective { | 
					
						
							| 
									
										
										
										
											2016-04-28 17:50:03 -07:00
										 |  |  |   constructor(el: ElementRef) { getDOM().addClass(el.nativeElement, 'compiled'); } | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-19 12:51:01 -07:00
										 |  |  | @Component({selector: 'test-cmp', template: ''}) | 
					
						
							| 
									
										
										
										
											2015-05-26 14:22:35 -07:00
										 |  |  | class TestComponent { | 
					
						
							|  |  |  |   text: string; | 
					
						
							|  |  |  |   constructor() { this.text = 'foo'; } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-09-08 20:37:20 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | function createTestComponent(template: string): ComponentFixture<TestComponent> { | 
					
						
							|  |  |  |   return TestBed.overrideComponent(TestComponent, {set: {template: template}}) | 
					
						
							|  |  |  |       .createComponent(TestComponent); | 
					
						
							|  |  |  | } |