| 
									
										
										
										
											2017-12-01 14:23:03 -08: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
 | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | import {NgForOfContext} from '@angular/common'; | 
					
						
							| 
									
										
										
										
											2018-06-14 15:45:21 +02:00
										 |  |  | import {ElementRef, TemplateRef, ViewContainerRef} from '@angular/core'; | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-31 15:45:46 +02:00
										 |  |  | import {EventEmitter} from '../..'; | 
					
						
							| 
									
										
										
										
											2018-09-21 18:38:13 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | import {AttributeMarker, QueryList, defineComponent, defineDirective, detectChanges} from '../../src/render3/index'; | 
					
						
							| 
									
										
										
										
											2018-10-12 18:49:00 -07:00
										 |  |  | import {getNativeByIndex} from '../../src/render3/util'; | 
					
						
							| 
									
										
										
										
											2018-10-29 21:55:58 -07:00
										 |  |  | import {bind, container, containerRefreshEnd, containerRefreshStart, directiveInject, element, elementContainerEnd, elementContainerStart, elementEnd, elementProperty, elementStart, embeddedViewEnd, embeddedViewStart, load, loadQueryList, reference, registerContentQuery, template, text} from '../../src/render3/instructions'; | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  | import {RenderFlags} from '../../src/render3/interfaces/definition'; | 
					
						
							| 
									
										
										
										
											2018-09-25 18:44:05 -07:00
										 |  |  | import {query, queryRefresh} from '../../src/render3/query'; | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  | import {getViewData} from '../../src/render3/state'; | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  | import {templateRefExtractor} from '../../src/render3/view_engine_compatibility_prebound'; | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  | import {NgForOf, NgIf, NgTemplateOutlet} from './common_with_def'; | 
					
						
							| 
									
										
										
										
											2018-10-05 21:23:41 -07:00
										 |  |  | import {ComponentFixture, TemplateFixture, createComponent, createDirective, renderComponent, getDirectiveOnNode} from './render_util'; | 
					
						
							| 
									
										
										
										
											2017-12-18 15:14:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-06 17:27:16 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 17:01:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-18 15:14:09 +01:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Helper function to check if a given candidate object resembles ElementRef | 
					
						
							|  |  |  |  * @param candidate | 
					
						
							| 
									
										
										
										
											2017-12-19 15:01:05 -08:00
										 |  |  |  * @returns true if `ElementRef`. | 
					
						
							| 
									
										
										
										
											2017-12-18 15:14:09 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | function isElementRef(candidate: any): boolean { | 
					
						
							|  |  |  |   return candidate.nativeElement != null; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Helper function to check if a given candidate object resembles TemplateRef | 
					
						
							|  |  |  |  * @param candidate | 
					
						
							| 
									
										
										
										
											2017-12-19 15:01:05 -08:00
										 |  |  |  * @returns true if `TemplateRef`. | 
					
						
							| 
									
										
										
										
											2017-12-18 15:14:09 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | function isTemplateRef(candidate: any): boolean { | 
					
						
							|  |  |  |   return candidate.createEmbeddedView != null && candidate.createComponent == null; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Helper function to check if a given candidate object resembles ViewContainerRef | 
					
						
							|  |  |  |  * @param candidate | 
					
						
							| 
									
										
										
										
											2017-12-19 15:01:05 -08:00
										 |  |  |  * @returns true if `ViewContainerRef`. | 
					
						
							| 
									
										
										
										
											2017-12-18 15:14:09 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | function isViewContainerRef(candidate: any): boolean { | 
					
						
							|  |  |  |   return candidate.createEmbeddedView != null && candidate.createComponent != null; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | describe('query', () => { | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |   it('should match projected query children', () => { | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |     const Child = createComponent('child', function(rf: RenderFlags, ctx: any) {}); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     let child1 = null; | 
					
						
							|  |  |  |     let child2 = null; | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |     const Cmp = createComponent( | 
					
						
							|  |  |  |         'cmp', | 
					
						
							|  |  |  |         function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |           /** | 
					
						
							|  |  |  |            * <child> | 
					
						
							|  |  |  |            *   <child> | 
					
						
							|  |  |  |            *   </child> | 
					
						
							|  |  |  |            * </child> | 
					
						
							|  |  |  |            * class Cmp { | 
					
						
							|  |  |  |            *   @ViewChildren(Child) query0; | 
					
						
							|  |  |  |            *   @ViewChildren(Child, {descend: true}) query1; | 
					
						
							|  |  |  |            * } | 
					
						
							|  |  |  |            */ | 
					
						
							|  |  |  |           if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |             elementStart(2, 'child'); | 
					
						
							|  |  |  |             { element(3, 'child'); } | 
					
						
							|  |  |  |             elementEnd(); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2018-10-05 21:23:41 -07:00
										 |  |  |             child1 = getDirectiveOnNode(2); | 
					
						
							|  |  |  |             child2 = getDirectiveOnNode(3); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |           } | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |         4, 0, [Child], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |           if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |             query(0, Child, false); | 
					
						
							|  |  |  |             query(1, Child, true); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |             let tmp: any; | 
					
						
							|  |  |  |             queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query0 = tmp as QueryList<any>); | 
					
						
							|  |  |  |             queryRefresh(tmp = load<QueryList<any>>(1)) && (ctx.query1 = tmp as QueryList<any>); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const parent = renderComponent(Cmp); | 
					
						
							|  |  |  |     expect((parent.query0 as QueryList<any>).toArray()).toEqual([child1]); | 
					
						
							|  |  |  |     expect((parent.query1 as QueryList<any>).toArray()).toEqual([child1, child2]); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2017-12-12 14:42:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |   describe('predicate', () => { | 
					
						
							|  |  |  |     describe('types', () => { | 
					
						
							| 
									
										
										
										
											2017-12-20 12:19:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |       it('should query using type predicate and read a specified token', () => { | 
					
						
							|  |  |  |         const Child = createDirective('child'); | 
					
						
							|  |  |  |         let elToQuery; | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * <div child></div> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren(Child, {read: ElementRef}) query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-07-27 14:56:15 -07:00
										 |  |  |                 element(1, 'div', ['child', '']); | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |                 elToQuery = getNativeByIndex(1, getViewData()); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             2, 0, [Child], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, Child, false, ElementRef); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2017-12-20 12:19:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |         const qList = (cmptInstance.query as QueryList<any>); | 
					
						
							|  |  |  |         expect(qList.length).toBe(1); | 
					
						
							|  |  |  |         expect(isElementRef(qList.first)).toBeTruthy(); | 
					
						
							|  |  |  |         expect(qList.first.nativeElement).toBe(elToQuery); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2017-12-20 17:35:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |       it('should query using type predicate and read another directive type', () => { | 
					
						
							|  |  |  |         const Child = createDirective('child'); | 
					
						
							|  |  |  |         const OtherChild = createDirective('otherChild'); | 
					
						
							|  |  |  |         let otherChildInstance; | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * <div child otherChild></div> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren(Child, {read: OtherChild}) query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 elementStart(1, 'div', ['child', '', 'otherChild', '']); | 
					
						
							| 
									
										
										
										
											2018-10-05 21:23:41 -07:00
										 |  |  |                 { otherChildInstance = getDirectiveOnNode(1, 1); } | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                 elementEnd(); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             2, 0, [Child, OtherChild], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 query(0, Child, false, OtherChild); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2017-12-20 17:35:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |         const qList = (cmptInstance.query as QueryList<any>); | 
					
						
							|  |  |  |         expect(qList.length).toBe(1); | 
					
						
							|  |  |  |         expect(qList.first).toBe(otherChildInstance); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2017-12-20 17:35:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |       it('should not add results to query if a requested token cant be read', () => { | 
					
						
							|  |  |  |         const Child = createDirective('child'); | 
					
						
							|  |  |  |         const OtherChild = createDirective('otherChild'); | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * <div child></div> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren(Child, {read: OtherChild}) query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-07-27 14:28:22 -07:00
										 |  |  |                 element(1, 'div', ['child', '']); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             2, 0, [Child, OtherChild], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 query(0, Child, false, OtherChild); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2017-12-20 17:35:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |         const qList = (cmptInstance.query as QueryList<any>); | 
					
						
							|  |  |  |         expect(qList.length).toBe(0); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2017-12-20 17:35:03 +01:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-12-20 12:19:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |     describe('local names', () => { | 
					
						
							| 
									
										
										
										
											2017-12-12 14:42:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |       it('should query for a single element and read ElementRef by default', () => { | 
					
						
							| 
									
										
										
										
											2017-12-12 14:42:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         let elToQuery; | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * <div #foo></div> | 
					
						
							|  |  |  |          * <div></div> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren('foo') query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-07-27 14:56:15 -07:00
										 |  |  |                 element(1, 'div', null, ['foo', '']); | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |                 elToQuery = getNativeByIndex(1, getViewData()); | 
					
						
							| 
									
										
										
										
											2018-07-27 14:28:22 -07:00
										 |  |  |                 element(3, 'div'); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             4, 0, [], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, ['foo'], false); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |         const qList = (cmptInstance.query as QueryList<any>); | 
					
						
							|  |  |  |         expect(qList.length).toBe(1); | 
					
						
							|  |  |  |         expect(qList.first.nativeElement).toEqual(elToQuery); | 
					
						
							| 
									
										
										
										
											2017-12-12 14:42:28 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |       it('should query multiple locals on the same element', () => { | 
					
						
							|  |  |  |         let elToQuery; | 
					
						
							| 
									
										
										
										
											2017-12-12 14:42:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         /** | 
					
						
							|  |  |  |          * <div #foo #bar></div> | 
					
						
							|  |  |  |          * <div></div> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren('foo') fooQuery; | 
					
						
							|  |  |  |          *  @ViewChildren('bar') barQuery; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-07-27 14:56:15 -07:00
										 |  |  |                 element(2, 'div', null, ['foo', '', 'bar', '']); | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |                 elToQuery = getNativeByIndex(2, getViewData()); | 
					
						
							| 
									
										
										
										
											2018-07-27 14:28:22 -07:00
										 |  |  |                 element(5, 'div'); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             6, 0, [], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, ['foo'], false); | 
					
						
							|  |  |  |                 query(1, ['bar'], false); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && | 
					
						
							|  |  |  |                     (ctx.fooQuery = tmp as QueryList<any>); | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(1)) && | 
					
						
							|  |  |  |                     (ctx.barQuery = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2018-03-15 12:18:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const cmptInstance = renderComponent(Cmpt); | 
					
						
							| 
									
										
										
										
											2018-03-15 12:18:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const fooList = (cmptInstance.fooQuery as QueryList<any>); | 
					
						
							|  |  |  |         expect(fooList.length).toBe(1); | 
					
						
							|  |  |  |         expect(fooList.first.nativeElement).toEqual(elToQuery); | 
					
						
							| 
									
										
										
										
											2018-03-15 12:18:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const barList = (cmptInstance.barQuery as QueryList<any>); | 
					
						
							|  |  |  |         expect(barList.length).toBe(1); | 
					
						
							|  |  |  |         expect(barList.first.nativeElement).toEqual(elToQuery); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2018-03-15 12:18:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |       it('should query for multiple elements and read ElementRef by default', () => { | 
					
						
							| 
									
										
										
										
											2018-03-15 12:18:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         let el1ToQuery; | 
					
						
							|  |  |  |         let el2ToQuery; | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * <div #foo></div> | 
					
						
							|  |  |  |          * <div></div> | 
					
						
							|  |  |  |          * <div #bar></div> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren('foo,bar') query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-07-27 14:56:15 -07:00
										 |  |  |                 element(1, 'div', null, ['foo', '']); | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |                 el1ToQuery = getNativeByIndex(1, getViewData()); | 
					
						
							| 
									
										
										
										
											2018-07-27 14:28:22 -07:00
										 |  |  |                 element(3, 'div'); | 
					
						
							| 
									
										
										
										
											2018-07-27 14:56:15 -07:00
										 |  |  |                 element(4, 'div', null, ['bar', '']); | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |                 el2ToQuery = getNativeByIndex(4, getViewData()); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             6, 0, [], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, ['foo', 'bar'], undefined); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2017-12-12 14:42:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |         const qList = (cmptInstance.query as QueryList<any>); | 
					
						
							|  |  |  |         expect(qList.length).toBe(2); | 
					
						
							|  |  |  |         expect(qList.first.nativeElement).toEqual(el1ToQuery); | 
					
						
							|  |  |  |         expect(qList.last.nativeElement).toEqual(el2ToQuery); | 
					
						
							| 
									
										
										
										
											2017-12-12 14:42:28 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |       it('should read ElementRef from an element when explicitly asked for', () => { | 
					
						
							| 
									
										
										
										
											2017-12-12 14:42:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         let elToQuery; | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * <div #foo></div> | 
					
						
							|  |  |  |          * <div></div> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren('foo', {read: ElementRef}) query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-07-27 14:56:15 -07:00
										 |  |  |                 element(1, 'div', null, ['foo', '']); | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |                 elToQuery = getNativeByIndex(1, getViewData()); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                 element(3, 'div'); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             4, 0, [], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, ['foo'], false); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2017-12-18 15:14:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |         const qList = (cmptInstance.query as QueryList<any>); | 
					
						
							|  |  |  |         expect(qList.length).toBe(1); | 
					
						
							|  |  |  |         expect(isElementRef(qList.first)).toBeTruthy(); | 
					
						
							|  |  |  |         expect(qList.first.nativeElement).toEqual(elToQuery); | 
					
						
							| 
									
										
										
										
											2017-12-18 15:14:09 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-26 17:22:41 +02:00
										 |  |  |       it('should query for <ng-container> and read ElementRef with a native element pointing to comment node', | 
					
						
							|  |  |  |          () => { | 
					
						
							|  |  |  |            let elToQuery; | 
					
						
							|  |  |  |            /** | 
					
						
							|  |  |  |             * <ng-container #foo></ng-container> | 
					
						
							|  |  |  |             * class Cmpt { | 
					
						
							| 
									
										
										
										
											2018-08-22 17:30:27 +02:00
										 |  |  |             *  @ViewChildren('foo', {read: ElementRef}) query; | 
					
						
							| 
									
										
										
										
											2018-07-26 17:22:41 +02:00
										 |  |  |             * } | 
					
						
							|  |  |  |             */ | 
					
						
							|  |  |  |            const Cmpt = createComponent( | 
					
						
							|  |  |  |                'cmpt', | 
					
						
							|  |  |  |                function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |                  if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                    elementContainerStart(1, null, ['foo', '']); | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |                    elToQuery = getNativeByIndex(1, getViewData()); | 
					
						
							| 
									
										
										
										
											2018-07-26 17:22:41 +02:00
										 |  |  |                    elementContainerEnd(); | 
					
						
							|  |  |  |                  } | 
					
						
							|  |  |  |                }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                3, 0, [], [], | 
					
						
							| 
									
										
										
										
											2018-07-26 17:22:41 +02:00
										 |  |  |                function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |                  if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                    query(0, ['foo'], false, ElementRef); | 
					
						
							| 
									
										
										
										
											2018-07-26 17:22:41 +02:00
										 |  |  |                  } | 
					
						
							|  |  |  |                  if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                    let tmp: any; | 
					
						
							|  |  |  |                    queryRefresh(tmp = load<QueryList<any>>(0)) && | 
					
						
							|  |  |  |                        (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |                  } | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |            const qList = (cmptInstance.query as QueryList<any>); | 
					
						
							|  |  |  |            expect(qList.length).toBe(1); | 
					
						
							|  |  |  |            expect(isElementRef(qList.first)).toBeTruthy(); | 
					
						
							|  |  |  |            expect(qList.first.nativeElement).toEqual(elToQuery); | 
					
						
							|  |  |  |          }); | 
					
						
							| 
									
										
										
										
											2018-08-08 11:13:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-22 17:30:27 +02:00
										 |  |  |       it('should query for <ng-container> and read ElementRef without explicit read option', () => { | 
					
						
							|  |  |  |         let elToQuery; | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * <ng-container #foo></ng-container> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren('foo') query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 elementContainerStart(1, null, ['foo', '']); | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |                 elToQuery = getNativeByIndex(1, getViewData()); | 
					
						
							| 
									
										
										
										
											2018-08-22 17:30:27 +02:00
										 |  |  |                 elementContainerEnd(); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             3, 0, [], [], | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, ['foo'], true); | 
					
						
							| 
									
										
										
										
											2018-08-22 17:30:27 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |         const qList = (cmptInstance.query as QueryList<any>); | 
					
						
							|  |  |  |         expect(qList.length).toBe(1); | 
					
						
							|  |  |  |         expect(isElementRef(qList.first)).toBeTruthy(); | 
					
						
							|  |  |  |         expect(qList.first.nativeElement).toEqual(elToQuery); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-08 11:13:37 +02:00
										 |  |  |       /** | 
					
						
							|  |  |  |        * BREAKING CHANGE: this tests asserts different behaviour as compared to Renderer2 when it | 
					
						
							|  |  |  |        * comes to descendants: false option and <ng-container>. | 
					
						
							|  |  |  |        * | 
					
						
							|  |  |  |        * Previous behaviour: queries with descendants: false would descend into <ng-container>. | 
					
						
							|  |  |  |        * New behaviour: queries with descendants: false would NOT descend into <ng-container>. | 
					
						
							|  |  |  |        * | 
					
						
							|  |  |  |        * Reasoning: the Renderer2 behaviour is inconsistent and hard to explain to users when it | 
					
						
							|  |  |  |        * comes to descendants: false interpretation (see | 
					
						
							|  |  |  |        * https://github.com/angular/angular/issues/14769#issuecomment-356609267) so we are changing
 | 
					
						
							|  |  |  |        * it in ngIvy. | 
					
						
							|  |  |  |        * | 
					
						
							|  |  |  |        * In ngIvy implementation queries with the descendants: false option are interpreted as | 
					
						
							|  |  |  |        * "don't descend" into children of a given element when looking for matches. In other words | 
					
						
							|  |  |  |        * only direct children of a given component / directive are checked for matches. This applies | 
					
						
							|  |  |  |        * to both regular elements (ex. <div>) and grouping elements (<ng-container>, | 
					
						
							|  |  |  |        * <ng-template>)). | 
					
						
							|  |  |  |        * | 
					
						
							|  |  |  |        * Grouping elements (<ng-container>, <ng-template>) are treated as regular elements since we | 
					
						
							|  |  |  |        * can query for <ng-container> and <ng-template>, so they behave like regular elements from | 
					
						
							|  |  |  |        * this point of view. | 
					
						
							|  |  |  |        */ | 
					
						
							|  |  |  |       it('should not descend into <ng-container> when descendants: false', () => { | 
					
						
							|  |  |  |         let elToQuery; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |           * <ng-container> | 
					
						
							|  |  |  |           *    <div #foo></div> | 
					
						
							|  |  |  |           * </ng-container> | 
					
						
							|  |  |  |           * class Cmpt { | 
					
						
							|  |  |  |           *  @ViewChildren('foo') deep; | 
					
						
							|  |  |  |           *  @ViewChildren('foo', {descendants: false}) shallow; | 
					
						
							|  |  |  |           * } | 
					
						
							|  |  |  |           */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 elementContainerStart(2); | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                   element(3, 'div', null, ['foo', '']); | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |                   elToQuery = getNativeByIndex(3, getViewData()); | 
					
						
							| 
									
										
										
										
											2018-08-08 11:13:37 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  |                 elementContainerEnd(); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             5, 0, [], [], | 
					
						
							| 
									
										
										
										
											2018-08-08 11:13:37 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, ['foo'], true, ElementRef); | 
					
						
							|  |  |  |                 query(1, ['foo'], false, ElementRef); | 
					
						
							| 
									
										
										
										
											2018-08-08 11:13:37 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.deep = tmp as QueryList<any>); | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(1)) && | 
					
						
							|  |  |  |                     (ctx.shallow = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const fixture = new ComponentFixture(Cmpt); | 
					
						
							|  |  |  |         const deepQList = fixture.component.deep; | 
					
						
							|  |  |  |         const shallowQList = fixture.component.shallow; | 
					
						
							|  |  |  |         expect(deepQList.length).toBe(1); | 
					
						
							|  |  |  |         expect(shallowQList.length).toBe(0); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2018-07-26 17:22:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |       it('should read ViewContainerRef from element nodes when explicitly asked for', () => { | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * <div #foo></div> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren('foo', {read: ViewContainerRef}) query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 element(1, 'div', null, ['foo', '']); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             3, 0, [], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, ['foo'], false, ViewContainerRef); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2017-12-18 15:14:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |         const qList = (cmptInstance.query as QueryList<any>); | 
					
						
							|  |  |  |         expect(qList.length).toBe(1); | 
					
						
							|  |  |  |         expect(isViewContainerRef(qList.first)).toBeTruthy(); | 
					
						
							| 
									
										
										
										
											2017-12-18 15:14:09 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |       it('should read ViewContainerRef from container nodes when explicitly asked for', () => { | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * <ng-template #foo></ng-template> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren('foo', {read: ViewContainerRef}) query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                 template(1, null, 0, 0, null, null, ['foo', '']); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             3, 0, [], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, ['foo'], false, ViewContainerRef); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2017-12-18 15:14:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |         const qList = (cmptInstance.query as QueryList<any>); | 
					
						
							|  |  |  |         expect(qList.length).toBe(1); | 
					
						
							|  |  |  |         expect(isViewContainerRef(qList.first)).toBeTruthy(); | 
					
						
							| 
									
										
										
										
											2017-12-18 15:14:09 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |       it('should read ElementRef with a native element pointing to comment DOM node from containers', | 
					
						
							|  |  |  |          () => { | 
					
						
							|  |  |  |            /** | 
					
						
							|  |  |  |             * <ng-template #foo></ng-template> | 
					
						
							|  |  |  |             * class Cmpt { | 
					
						
							|  |  |  |             *  @ViewChildren('foo', {read: ElementRef}) query; | 
					
						
							|  |  |  |             * } | 
					
						
							|  |  |  |             */ | 
					
						
							|  |  |  |            const Cmpt = createComponent( | 
					
						
							|  |  |  |                'cmpt', | 
					
						
							|  |  |  |                function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |                  if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                    template(1, null, 0, 0, null, null, ['foo', '']); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                  } | 
					
						
							|  |  |  |                }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                3, 0, [], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                function(rf: RenderFlags, ctx: any) { | 
					
						
							| 
									
										
										
										
											2017-12-18 15:14:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                  if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                    query(0, ['foo'], false, ElementRef); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                  } | 
					
						
							|  |  |  |                  if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                    let tmp: any; | 
					
						
							|  |  |  |                    queryRefresh(tmp = load<QueryList<any>>(0)) && | 
					
						
							|  |  |  |                        (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |                  } | 
					
						
							|  |  |  |                }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |            const qList = (cmptInstance.query as QueryList<any>); | 
					
						
							|  |  |  |            expect(qList.length).toBe(1); | 
					
						
							|  |  |  |            expect(isElementRef(qList.first)).toBeTruthy(); | 
					
						
							|  |  |  |            expect(qList.first.nativeElement.nodeType).toBe(8);  // Node.COMMENT_NODE = 8
 | 
					
						
							| 
									
										
										
										
											2017-12-18 15:14:09 +01:00
										 |  |  |          }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |       it('should read TemplateRef from container nodes by default', () => { | 
					
						
							|  |  |  |         // http://plnkr.co/edit/BVpORly8wped9I3xUYsX?p=preview
 | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * <ng-template #foo></ng-template> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren('foo') query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                 template(1, null, 0, 0, null, null, ['foo', '']); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             3, 0, [], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, ['foo'], undefined); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2017-12-18 15:14:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |         const qList = (cmptInstance.query as QueryList<any>); | 
					
						
							|  |  |  |         expect(qList.length).toBe(1); | 
					
						
							|  |  |  |         expect(isTemplateRef(qList.first)).toBeTruthy(); | 
					
						
							| 
									
										
										
										
											2017-12-18 15:14:09 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |       it('should read TemplateRef from container nodes when explicitly asked for', () => { | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * <ng-template #foo></ng-template> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren('foo', {read: TemplateRef}) query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                 template(1, null, 0, 0, null, null, ['foo', '']); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             3, 0, [], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, ['foo'], false, TemplateRef); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2017-12-18 15:14:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |         const qList = (cmptInstance.query as QueryList<any>); | 
					
						
							|  |  |  |         expect(qList.length).toBe(1); | 
					
						
							|  |  |  |         expect(isTemplateRef(qList.first)).toBeTruthy(); | 
					
						
							| 
									
										
										
										
											2017-12-18 15:14:09 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |       it('should read component instance if element queried for is a component host', () => { | 
					
						
							|  |  |  |         const Child = createComponent('child', function(rf: RenderFlags, ctx: any) {}); | 
					
						
							| 
									
										
										
										
											2017-12-18 15:14:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         let childInstance; | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * <child #foo></child> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren('foo') query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 element(1, 'child', null, ['foo', '']); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2018-10-05 21:23:41 -07:00
										 |  |  |                 childInstance = getDirectiveOnNode(1); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             3, 0, [Child], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, ['foo'], true); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2017-12-19 16:51:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |         const qList = (cmptInstance.query as QueryList<any>); | 
					
						
							|  |  |  |         expect(qList.length).toBe(1); | 
					
						
							|  |  |  |         expect(qList.first).toBe(childInstance); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2017-12-19 16:51:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |       it('should read component instance with explicit exportAs', () => { | 
					
						
							|  |  |  |         let childInstance: Child; | 
					
						
							| 
									
										
										
										
											2017-12-19 16:51:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         class Child { | 
					
						
							|  |  |  |           static ngComponentDef = defineComponent({ | 
					
						
							|  |  |  |             type: Child, | 
					
						
							|  |  |  |             selectors: [['child']], | 
					
						
							|  |  |  |             factory: () => childInstance = new Child(), | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |             consts: 0, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             vars: 0, | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             template: (rf: RenderFlags, ctx: Child) => {}, | 
					
						
							|  |  |  |             exportAs: 'child' | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-03-14 14:29:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         /** | 
					
						
							|  |  |  |          * <child #foo="child"></child> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren('foo') query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 element(1, 'child', null, ['foo', 'child']); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             3, 0, [Child], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, ['foo'], true); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2018-03-14 14:29:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |         const qList = (cmptInstance.query as QueryList<any>); | 
					
						
							|  |  |  |         expect(qList.length).toBe(1); | 
					
						
							|  |  |  |         expect(qList.first).toBe(childInstance !); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2018-03-14 14:29:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |       it('should read directive instance if element queried for has an exported directive with a matching name', | 
					
						
							|  |  |  |          () => { | 
					
						
							|  |  |  |            const Child = createDirective('child', {exportAs: 'child'}); | 
					
						
							| 
									
										
										
										
											2018-03-14 14:29:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |            let childInstance; | 
					
						
							|  |  |  |            /** | 
					
						
							|  |  |  |             * <div #foo="child" child></div> | 
					
						
							|  |  |  |             * class Cmpt { | 
					
						
							|  |  |  |             *  @ViewChildren('foo') query; | 
					
						
							|  |  |  |             * } | 
					
						
							|  |  |  |             */ | 
					
						
							|  |  |  |            const Cmpt = createComponent( | 
					
						
							|  |  |  |                'cmpt', | 
					
						
							|  |  |  |                function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |                  if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                    element(1, 'div', ['child', ''], ['foo', 'child']); | 
					
						
							|  |  |  |                  } | 
					
						
							|  |  |  |                  if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2018-10-05 21:23:41 -07:00
										 |  |  |                    childInstance = getDirectiveOnNode(1); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                  } | 
					
						
							|  |  |  |                }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                3, 0, [Child], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |                  if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                    query(0, ['foo'], true); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                  } | 
					
						
							|  |  |  |                  if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                    let tmp: any; | 
					
						
							|  |  |  |                    queryRefresh(tmp = load<QueryList<any>>(0)) && | 
					
						
							|  |  |  |                        (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |                  } | 
					
						
							|  |  |  |                }); | 
					
						
							| 
									
										
										
										
											2017-12-19 16:51:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |            const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |            const qList = (cmptInstance.query as QueryList<any>); | 
					
						
							|  |  |  |            expect(qList.length).toBe(1); | 
					
						
							|  |  |  |            expect(qList.first).toBe(childInstance); | 
					
						
							|  |  |  |          }); | 
					
						
							| 
									
										
										
										
											2017-12-19 16:51:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |       it('should read all matching directive instances from a given element', () => { | 
					
						
							|  |  |  |         const Child1 = createDirective('child1', {exportAs: 'child1'}); | 
					
						
							|  |  |  |         const Child2 = createDirective('child2', {exportAs: 'child2'}); | 
					
						
							| 
									
										
										
										
											2017-12-19 16:51:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         let child1Instance, child2Instance; | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * <div #foo="child1" child1 #bar="child2" child2></div> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren('foo, bar') query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 element(1, 'div', ['child1', '', 'child2', ''], ['foo', 'child1', 'bar', 'child2']); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2018-10-05 21:23:41 -07:00
										 |  |  |                 child1Instance = getDirectiveOnNode(1, 0); | 
					
						
							|  |  |  |                 child2Instance = getDirectiveOnNode(1, 1); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             4, 0, [Child1, Child2], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, ['foo', 'bar'], true); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2017-12-19 16:51:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |         const qList = (cmptInstance.query as QueryList<any>); | 
					
						
							|  |  |  |         expect(qList.length).toBe(2); | 
					
						
							|  |  |  |         expect(qList.first).toBe(child1Instance); | 
					
						
							|  |  |  |         expect(qList.last).toBe(child2Instance); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2017-12-19 16:51:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |       it('should read multiple locals exporting the same directive from a given element', () => { | 
					
						
							|  |  |  |         const Child = createDirective('child', {exportAs: 'child'}); | 
					
						
							|  |  |  |         let childInstance; | 
					
						
							| 
									
										
										
										
											2018-03-15 12:18:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         /** | 
					
						
							|  |  |  |          * <div child #foo="child" #bar="child"></div> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren('foo') fooQuery; | 
					
						
							|  |  |  |          *  @ViewChildren('bar') barQuery; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 element(2, 'div', ['child', ''], ['foo', 'child', 'bar', 'child']); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2018-10-05 21:23:41 -07:00
										 |  |  |                 childInstance = getDirectiveOnNode(2); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             5, 0, [Child], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, ['foo'], true); | 
					
						
							|  |  |  |                 query(1, ['bar'], true); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && | 
					
						
							|  |  |  |                     (ctx.fooQuery = tmp as QueryList<any>); | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(1)) && | 
					
						
							|  |  |  |                     (ctx.barQuery = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2018-03-15 12:18:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const cmptInstance = renderComponent(Cmpt); | 
					
						
							| 
									
										
										
										
											2018-03-15 12:18:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const fooList = cmptInstance.fooQuery as QueryList<any>; | 
					
						
							|  |  |  |         expect(fooList.length).toBe(1); | 
					
						
							|  |  |  |         expect(fooList.first).toBe(childInstance); | 
					
						
							| 
									
										
										
										
											2018-03-15 12:18:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const barList = cmptInstance.barQuery as QueryList<any>; | 
					
						
							|  |  |  |         expect(barList.length).toBe(1); | 
					
						
							|  |  |  |         expect(barList.first).toBe(childInstance); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2018-03-15 12:18:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |       it('should match on exported directive name and read a requested token', () => { | 
					
						
							|  |  |  |         const Child = createDirective('child', {exportAs: 'child'}); | 
					
						
							| 
									
										
										
										
											2017-12-19 16:51:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         let div; | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * <div #foo="child" child></div> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren('foo', {read: ElementRef}) query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-07-27 14:56:15 -07:00
										 |  |  |                 element(1, 'div', ['child', ''], ['foo', 'child']); | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |                 div = getNativeByIndex(1, getViewData()); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             3, 0, [Child], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, ['foo'], undefined, ElementRef); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2017-12-19 16:51:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |         const qList = (cmptInstance.query as QueryList<any>); | 
					
						
							|  |  |  |         expect(qList.length).toBe(1); | 
					
						
							|  |  |  |         expect(qList.first.nativeElement).toBe(div); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2017-12-19 16:51:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |       it('should support reading a mix of ElementRef and directive instances', () => { | 
					
						
							|  |  |  |         const Child = createDirective('child', {exportAs: 'child'}); | 
					
						
							| 
									
										
										
										
											2017-12-19 16:51:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         let childInstance, div; | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * <div #foo #bar="child" child></div> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren('foo, bar') query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-07-27 14:56:15 -07:00
										 |  |  |                 element(1, 'div', ['child', ''], ['foo', '', 'bar', 'child']); | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |                 div = getNativeByIndex(1, getViewData()); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2018-10-05 21:23:41 -07:00
										 |  |  |                 childInstance = getDirectiveOnNode(1); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             4, 0, [Child], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, ['foo', 'bar'], undefined); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2017-12-19 16:51:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |         const qList = (cmptInstance.query as QueryList<any>); | 
					
						
							|  |  |  |         expect(qList.length).toBe(2); | 
					
						
							|  |  |  |         expect(qList.first.nativeElement).toBe(div); | 
					
						
							|  |  |  |         expect(qList.last).toBe(childInstance); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2017-12-19 16:51:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-29 21:55:58 -07:00
										 |  |  |       it('should not add results to selector-based query if a requested token cant be read', () => { | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const Child = createDirective('child'); | 
					
						
							| 
									
										
										
										
											2017-12-20 17:35:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         /** | 
					
						
							|  |  |  |          * <div #foo></div> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren('foo', {read: Child}) query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 element(1, 'div', ['foo', '']); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             3, 0, [Child], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 query(0, ['foo'], false, Child); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2017-12-20 17:35:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-29 21:55:58 -07:00
										 |  |  |         const {component} = new ComponentFixture(Cmpt); | 
					
						
							|  |  |  |         const qList = component.query; | 
					
						
							|  |  |  |         expect(qList.length).toBe(0); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should not add results to directive-based query if requested token cant be read', () => { | 
					
						
							|  |  |  |         const Child = createDirective('child'); | 
					
						
							|  |  |  |         const OtherChild = createDirective('otherchild'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * <div child></div> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren(Child, {read: OtherChild}) query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 element(1, 'div', ['child', '']); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             2, 0, [Child, OtherChild], [], | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 query(0, Child, false, OtherChild); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const {component} = new ComponentFixture(Cmpt); | 
					
						
							|  |  |  |         const qList = component.query; | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         expect(qList.length).toBe(0); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2017-12-20 17:35:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-29 21:55:58 -07:00
										 |  |  |       it('should not add results to directive-based query if only read token matches', () => { | 
					
						
							|  |  |  |         const Child = createDirective('child'); | 
					
						
							|  |  |  |         const OtherChild = createDirective('otherchild'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * <div child></div> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren(OtherChild, {read: Child}) query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 element(1, 'div', ['child', '']); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             2, 0, [Child, OtherChild], [], | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 query(0, OtherChild, false, Child); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const {component} = new ComponentFixture(Cmpt); | 
					
						
							|  |  |  |         const qList = component.query; | 
					
						
							|  |  |  |         expect(qList.length).toBe(0); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should not add results to TemplateRef-based query if only read token matches', () => { | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * <div></div> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren(TemplateRef, {read: ElementRef}) query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 element(1, 'div'); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             2, 0, [], [], | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 query(0, TemplateRef as any, false, ElementRef); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const {component} = new ComponentFixture(Cmpt); | 
					
						
							|  |  |  |         const qList = component.query; | 
					
						
							|  |  |  |         expect(qList.length).toBe(0); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should match using string selector and directive as a read argument', () => { | 
					
						
							|  |  |  |         const Child = createDirective('child'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * <div child #foo></div> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren('foo', {read: Child}) query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 element(1, 'div', ['child', ''], ['foo', '']); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             3, 0, [Child], [], | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 query(0, ['foo'], false, Child); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const {component} = new ComponentFixture(Cmpt); | 
					
						
							|  |  |  |         const qList = component.query; | 
					
						
							|  |  |  |         expect(qList.length).toBe(1); | 
					
						
							|  |  |  |         expect(qList.first instanceof Child).toBeTruthy(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should not add results to the query in case no match found (via TemplateRef)', () => { | 
					
						
							|  |  |  |         const Child = createDirective('child'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * <div child></div> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren(TemplateRef) query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 element(1, 'div', ['child', '']); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             2, 0, [Child], [], | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 query(0, TemplateRef as any, false); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const {component} = new ComponentFixture(Cmpt); | 
					
						
							|  |  |  |         const qList = component.query; | 
					
						
							|  |  |  |         expect(qList.length).toBe(0); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should query templates if the type is TemplateRef (and respect "read" option)', () => { | 
					
						
							|  |  |  |         function Cmpt_Template_1(rf: RenderFlags, ctx1: any) { | 
					
						
							|  |  |  |           if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |             elementStart(0, 'div'); | 
					
						
							|  |  |  |             text(1, 'Test'); | 
					
						
							|  |  |  |             elementEnd(); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * <ng-template #foo><div>Test</div></ng-template> | 
					
						
							|  |  |  |          * <ng-template #bar><div>Test</div></ng-template> | 
					
						
							|  |  |  |          * <ng-template #baz><div>Test</div></ng-template> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *   @ViewChildren(TemplateRef) tmplQuery; | 
					
						
							|  |  |  |          *   @ViewChildren(TemplateRef, {read: ElementRef}) elemQuery; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							|  |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 template(2, Cmpt_Template_1, 2, 0, null, null, ['foo', ''], templateRefExtractor); | 
					
						
							|  |  |  |                 template(3, Cmpt_Template_1, 2, 0, null, null, ['bar', ''], templateRefExtractor); | 
					
						
							|  |  |  |                 template(4, Cmpt_Template_1, 2, 0, null, null, ['baz', ''], templateRefExtractor); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             5, 0, [], [], | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 query(0, TemplateRef as any, false); | 
					
						
							|  |  |  |                 query(1, TemplateRef as any, false, ElementRef); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && | 
					
						
							|  |  |  |                     (ctx.tmplQuery = tmp as QueryList<any>); | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(1)) && | 
					
						
							|  |  |  |                     (ctx.elemQuery = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const {component} = new ComponentFixture(Cmpt); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // check template-based query set
 | 
					
						
							|  |  |  |         const tmplQList = component.tmplQuery; | 
					
						
							|  |  |  |         expect(tmplQList.length).toBe(3); | 
					
						
							|  |  |  |         expect(isTemplateRef(tmplQList.first)).toBeTruthy(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // check element-based query set
 | 
					
						
							|  |  |  |         const elemQList = component.elemQuery; | 
					
						
							|  |  |  |         expect(elemQList.length).toBe(3); | 
					
						
							|  |  |  |         expect(isElementRef(elemQList.first)).toBeTruthy(); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2017-12-12 14:42:28 +01:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe('view boundaries', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |     describe('ViewContainerRef', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-11 11:51:16 +02:00
										 |  |  |       let directiveInstances: ViewContainerManipulatorDirective[] = []; | 
					
						
							| 
									
										
										
										
											2018-06-01 17:01:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       class ViewContainerManipulatorDirective { | 
					
						
							|  |  |  |         static ngDirectiveDef = defineDirective({ | 
					
						
							|  |  |  |           type: ViewContainerManipulatorDirective, | 
					
						
							|  |  |  |           selectors: [['', 'vc', '']], | 
					
						
							|  |  |  |           factory: () => { | 
					
						
							| 
									
										
										
										
											2018-06-11 11:51:16 +02:00
										 |  |  |             const directiveInstance = | 
					
						
							| 
									
										
										
										
											2018-09-21 18:38:13 -07:00
										 |  |  |                 new ViewContainerManipulatorDirective(directiveInject(ViewContainerRef as any)); | 
					
						
							| 
									
										
										
										
											2018-06-11 11:51:16 +02:00
										 |  |  |             directiveInstances.push(directiveInstance); | 
					
						
							|  |  |  |             return directiveInstance; | 
					
						
							| 
									
										
										
										
											2018-06-01 17:01:24 +02:00
										 |  |  |           } | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         constructor(private _vcRef: ViewContainerRef) {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         insertTpl(tpl: TemplateRef<{}>, ctx: {}, idx?: number) { | 
					
						
							|  |  |  |           this._vcRef.createEmbeddedView(tpl, ctx, idx); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         remove(index?: number) { this._vcRef.remove(index); } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-11 11:51:16 +02:00
										 |  |  |       beforeEach(() => { directiveInstances = []; }); | 
					
						
							| 
									
										
										
										
											2018-06-01 17:01:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |       it('should report results in views inserted / removed by ngIf', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |         function Cmpt_Template_1(rf: RenderFlags, ctx1: any) { | 
					
						
							|  |  |  |           if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |             element(0, 'div', null, ['foo', '']); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |         /** | 
					
						
							|  |  |  |          * <ng-template [ngIf]="value"> | 
					
						
							|  |  |  |          *    <div #foo></div> | 
					
						
							|  |  |  |          * </ng-template> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren('foo') query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                 template(1, Cmpt_Template_1, 2, 0, null, ['ngIf', '']); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 elementProperty(1, 'ngIf', bind(ctx.value)); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             3, 1, [NgIf], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, ['foo'], true); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         const fixture = new ComponentFixture(Cmpt); | 
					
						
							|  |  |  |         const qList = fixture.component.query; | 
					
						
							|  |  |  |         expect(qList.length).toBe(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         fixture.component.value = true; | 
					
						
							|  |  |  |         fixture.update(); | 
					
						
							|  |  |  |         expect(qList.length).toBe(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         fixture.component.value = false; | 
					
						
							|  |  |  |         fixture.update(); | 
					
						
							|  |  |  |         expect(qList.length).toBe(0); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |       it('should report results in views inserted / removed by ngFor', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |         function Cmpt_Template_1(rf1: RenderFlags, row: NgForOfContext<string>) { | 
					
						
							|  |  |  |           if (rf1 & RenderFlags.Create) { | 
					
						
							|  |  |  |             element(0, 'div', null, ['foo', '']); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           if (rf1 & RenderFlags.Update) { | 
					
						
							|  |  |  |             elementProperty(0, 'id', bind(row.$implicit)); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |         /** | 
					
						
							|  |  |  |          * <ng-template ngFor let-item [ngForOf]="value"> | 
					
						
							|  |  |  |          *    <div #foo [id]="item"></div> | 
					
						
							|  |  |  |          * </ng-template> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren('foo') query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         class Cmpt { | 
					
						
							| 
									
										
										
										
											2018-06-18 16:38:33 -07:00
										 |  |  |           // TODO(issue/24571): remove '!'.
 | 
					
						
							|  |  |  |           value !: string[]; | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |           query: any; | 
					
						
							|  |  |  |           static ngComponentDef = defineComponent({ | 
					
						
							|  |  |  |             type: Cmpt, | 
					
						
							|  |  |  |             factory: () => new Cmpt(), | 
					
						
							|  |  |  |             selectors: [['my-app']], | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             consts: 3, | 
					
						
							|  |  |  |             vars: 1, | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             template: function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                 template(1, Cmpt_Template_1, 2, 1, null, ['ngForOf', '']); | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 elementProperty(1, 'ngForOf', bind(ctx.value)); | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             }, | 
					
						
							|  |  |  |             viewQuery: function(rf: RenderFlags, ctx: Cmpt) { | 
					
						
							|  |  |  |               let tmp: any; | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, ['foo'], true); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             directives: () => [NgForOf] | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |         const fixture = new ComponentFixture(Cmpt); | 
					
						
							|  |  |  |         const qList = fixture.component.query; | 
					
						
							|  |  |  |         expect(qList.length).toBe(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         fixture.component.value = ['a', 'b', 'c']; | 
					
						
							|  |  |  |         fixture.update(); | 
					
						
							|  |  |  |         expect(qList.length).toBe(3); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         fixture.component.value.splice(1, 1);  // remove "b"
 | 
					
						
							|  |  |  |         fixture.update(); | 
					
						
							|  |  |  |         expect(qList.length).toBe(2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // make sure that a proper element was removed from query results
 | 
					
						
							|  |  |  |         expect(qList.first.nativeElement.id).toBe('a'); | 
					
						
							|  |  |  |         expect(qList.last.nativeElement.id).toBe('c'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 17:01:24 +02:00
										 |  |  |       // https://stackblitz.com/edit/angular-rrmmuf?file=src/app/app.component.ts
 | 
					
						
							|  |  |  |       it('should report results when different instances of TemplateRef are inserted into one ViewContainerRefs', | 
					
						
							|  |  |  |          () => { | 
					
						
							|  |  |  |            let tpl1: TemplateRef<{}>; | 
					
						
							|  |  |  |            let tpl2: TemplateRef<{}>; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |            function Cmpt_Template_1(rf: RenderFlags, ctx: {idx: number}) { | 
					
						
							|  |  |  |              if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                element(0, 'div', null, ['foo', '']); | 
					
						
							|  |  |  |              } | 
					
						
							|  |  |  |              if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                elementProperty(0, 'id', bind('foo1_' + ctx.idx)); | 
					
						
							|  |  |  |              } | 
					
						
							|  |  |  |            } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            function Cmpt_Template_5(rf: RenderFlags, ctx: {idx: number}) { | 
					
						
							|  |  |  |              if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                element(0, 'div', null, ['foo', '']); | 
					
						
							|  |  |  |              } | 
					
						
							|  |  |  |              if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                elementProperty(0, 'id', bind('foo2_' + ctx.idx)); | 
					
						
							|  |  |  |              } | 
					
						
							|  |  |  |            } | 
					
						
							| 
									
										
										
										
											2018-06-01 17:01:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |            /** | 
					
						
							|  |  |  |             * <ng-template #tpl1 let-idx="idx"> | 
					
						
							|  |  |  |             *   <div #foo [id]="'foo1_'+idx"></div> | 
					
						
							|  |  |  |             * </ng-template> | 
					
						
							|  |  |  |             * | 
					
						
							|  |  |  |             * <div #foo id="middle"></div> | 
					
						
							|  |  |  |             * | 
					
						
							|  |  |  |             * <ng-template #tpl2 let-idx="idx"> | 
					
						
							|  |  |  |             *   <div #foo [id]="'foo2_'+idx"></div> | 
					
						
							|  |  |  |             * </ng-template> | 
					
						
							|  |  |  |             * | 
					
						
							|  |  |  |             * <ng-template viewInserter #vi="vi"></ng-template> | 
					
						
							|  |  |  |             */ | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |            const Cmpt = createComponent( | 
					
						
							|  |  |  |                'cmpt', | 
					
						
							|  |  |  |                function(rf: RenderFlags, ctx: any) { | 
					
						
							| 
									
										
										
										
											2018-06-01 17:01:24 +02:00
										 |  |  |                  if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                    template( | 
					
						
							| 
									
										
										
										
											2018-09-25 18:44:05 -07:00
										 |  |  |                        1, Cmpt_Template_1, 2, 1, null, null, ['tpl1', ''], templateRefExtractor); | 
					
						
							| 
									
										
										
										
											2018-08-14 16:25:01 +02:00
										 |  |  |                    element(3, 'div', ['id', 'middle'], ['foo', '']); | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                    template( | 
					
						
							| 
									
										
										
										
											2018-09-25 18:44:05 -07:00
										 |  |  |                        5, Cmpt_Template_5, 2, 1, null, null, ['tpl2', ''], templateRefExtractor); | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                    template(7, null, 0, 0, null, [AttributeMarker.SelectOnly, 'vc']); | 
					
						
							| 
									
										
										
										
											2018-06-01 17:01:24 +02:00
										 |  |  |                  } | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 17:01:24 +02:00
										 |  |  |                  if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2018-08-14 16:25:01 +02:00
										 |  |  |                    tpl1 = reference(2); | 
					
						
							|  |  |  |                    tpl2 = reference(6); | 
					
						
							| 
									
										
										
										
											2018-06-01 17:01:24 +02:00
										 |  |  |                  } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                }, | 
					
						
							| 
									
										
										
										
											2018-08-21 00:03:21 -07:00
										 |  |  |                9, 0, [ViewContainerManipulatorDirective], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                function(rf: RenderFlags, ctx: any) { | 
					
						
							| 
									
										
										
										
											2018-06-01 17:01:24 +02:00
										 |  |  |                  if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                    query(0, ['foo'], true); | 
					
						
							| 
									
										
										
										
											2018-06-01 17:01:24 +02:00
										 |  |  |                  } | 
					
						
							|  |  |  |                  if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                    let tmp: any; | 
					
						
							|  |  |  |                    queryRefresh(tmp = load<QueryList<any>>(0)) && | 
					
						
							|  |  |  |                        (ctx.query = tmp as QueryList<any>); | 
					
						
							| 
									
										
										
										
											2018-06-01 17:01:24 +02:00
										 |  |  |                  } | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                }); | 
					
						
							| 
									
										
										
										
											2018-06-01 17:01:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |            const fixture = new ComponentFixture(Cmpt); | 
					
						
							|  |  |  |            const qList = fixture.component.query; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            expect(qList.length).toBe(1); | 
					
						
							|  |  |  |            expect(qList.first.nativeElement.getAttribute('id')).toBe('middle'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-11 11:51:16 +02:00
										 |  |  |            directiveInstances[0].insertTpl(tpl1 !, {idx: 0}, 0); | 
					
						
							|  |  |  |            directiveInstances[0].insertTpl(tpl2 !, {idx: 1}, 1); | 
					
						
							| 
									
										
										
										
											2018-06-01 17:01:24 +02:00
										 |  |  |            fixture.update(); | 
					
						
							|  |  |  |            expect(qList.length).toBe(3); | 
					
						
							|  |  |  |            let qListArr = qList.toArray(); | 
					
						
							|  |  |  |            expect(qListArr[0].nativeElement.getAttribute('id')).toBe('foo1_0'); | 
					
						
							|  |  |  |            expect(qListArr[1].nativeElement.getAttribute('id')).toBe('middle'); | 
					
						
							|  |  |  |            expect(qListArr[2].nativeElement.getAttribute('id')).toBe('foo2_1'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-11 11:51:16 +02:00
										 |  |  |            directiveInstances[0].insertTpl(tpl1 !, {idx: 1}, 1); | 
					
						
							| 
									
										
										
										
											2018-06-01 17:01:24 +02:00
										 |  |  |            fixture.update(); | 
					
						
							|  |  |  |            expect(qList.length).toBe(4); | 
					
						
							|  |  |  |            qListArr = qList.toArray(); | 
					
						
							|  |  |  |            expect(qListArr[0].nativeElement.getAttribute('id')).toBe('foo1_0'); | 
					
						
							|  |  |  |            expect(qListArr[1].nativeElement.getAttribute('id')).toBe('foo1_1'); | 
					
						
							|  |  |  |            expect(qListArr[2].nativeElement.getAttribute('id')).toBe('middle'); | 
					
						
							|  |  |  |            expect(qListArr[3].nativeElement.getAttribute('id')).toBe('foo2_1'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-11 11:51:16 +02:00
										 |  |  |            directiveInstances[0].remove(1); | 
					
						
							| 
									
										
										
										
											2018-06-01 17:01:24 +02:00
										 |  |  |            fixture.update(); | 
					
						
							|  |  |  |            expect(qList.length).toBe(3); | 
					
						
							|  |  |  |            qListArr = qList.toArray(); | 
					
						
							|  |  |  |            expect(qListArr[0].nativeElement.getAttribute('id')).toBe('foo1_0'); | 
					
						
							|  |  |  |            expect(qListArr[1].nativeElement.getAttribute('id')).toBe('middle'); | 
					
						
							|  |  |  |            expect(qListArr[2].nativeElement.getAttribute('id')).toBe('foo2_1'); | 
					
						
							| 
									
										
										
										
											2018-06-11 11:51:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |            directiveInstances[0].remove(1); | 
					
						
							|  |  |  |            fixture.update(); | 
					
						
							|  |  |  |            expect(qList.length).toBe(2); | 
					
						
							|  |  |  |            qListArr = qList.toArray(); | 
					
						
							|  |  |  |            expect(qListArr[0].nativeElement.getAttribute('id')).toBe('foo1_0'); | 
					
						
							|  |  |  |            expect(qListArr[1].nativeElement.getAttribute('id')).toBe('middle'); | 
					
						
							|  |  |  |          }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // https://stackblitz.com/edit/angular-7vvo9j?file=src%2Fapp%2Fapp.component.ts
 | 
					
						
							|  |  |  |       it('should report results when the same TemplateRef is inserted into different ViewContainerRefs', | 
					
						
							|  |  |  |          () => { | 
					
						
							|  |  |  |            let tpl: TemplateRef<{}>; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |            function Cmpt_Template_1(rf: RenderFlags, ctx: {idx: number, container_idx: number}) { | 
					
						
							|  |  |  |              if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                element(0, 'div', null, ['foo', '']); | 
					
						
							|  |  |  |              } | 
					
						
							|  |  |  |              if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                elementProperty(0, 'id', bind('foo_' + ctx.container_idx + '_' + ctx.idx)); | 
					
						
							|  |  |  |              } | 
					
						
							|  |  |  |            } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-11 11:51:16 +02:00
										 |  |  |            /** | 
					
						
							|  |  |  |             * <ng-template #tpl let-idx="idx" let-container_idx="container_idx"> | 
					
						
							|  |  |  |             *   <div #foo [id]="'foo_'+container_idx+'_'+idx"></div> | 
					
						
							|  |  |  |             * </ng-template> | 
					
						
							|  |  |  |             * | 
					
						
							|  |  |  |             * <ng-template viewInserter #vi1="vi"></ng-template> | 
					
						
							|  |  |  |             * <ng-template viewInserter #vi2="vi"></ng-template> | 
					
						
							|  |  |  |             */ | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |            class Cmpt { | 
					
						
							|  |  |  |              query: any; | 
					
						
							|  |  |  |              static ngComponentDef = defineComponent({ | 
					
						
							|  |  |  |                type: Cmpt, | 
					
						
							|  |  |  |                factory: () => new Cmpt(), | 
					
						
							|  |  |  |                selectors: [['my-app']], | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                consts: 5, | 
					
						
							|  |  |  |                vars: 0, | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                template: function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |                  let tmp: any; | 
					
						
							| 
									
										
										
										
											2018-06-11 11:51:16 +02:00
										 |  |  |                  if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-25 18:44:05 -07:00
										 |  |  |                    template(1, Cmpt_Template_1, 2, 1, null, [], ['tpl', ''], templateRefExtractor); | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                    template(3, null, 0, 0, null, [AttributeMarker.SelectOnly, 'vc']); | 
					
						
							|  |  |  |                    template(4, null, 0, 0, null, [AttributeMarker.SelectOnly, 'vc']); | 
					
						
							| 
									
										
										
										
											2018-06-11 11:51:16 +02:00
										 |  |  |                  } | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-11 11:51:16 +02:00
										 |  |  |                  if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2018-08-14 16:25:01 +02:00
										 |  |  |                    tpl = reference(2); | 
					
						
							| 
									
										
										
										
											2018-06-11 11:51:16 +02:00
										 |  |  |                  } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                }, | 
					
						
							|  |  |  |                viewQuery: (rf: RenderFlags, cmpt: Cmpt) => { | 
					
						
							|  |  |  |                  let tmp: any; | 
					
						
							|  |  |  |                  if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                    query(0, ['foo'], true); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                  } | 
					
						
							|  |  |  |                  if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                    queryRefresh(tmp = load<QueryList<any>>(0)) && | 
					
						
							|  |  |  |                        (cmpt.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |                  } | 
					
						
							|  |  |  |                }, | 
					
						
							|  |  |  |                directives: () => [ViewContainerManipulatorDirective], | 
					
						
							|  |  |  |              }); | 
					
						
							|  |  |  |            } | 
					
						
							| 
									
										
										
										
											2018-06-11 11:51:16 +02:00
										 |  |  |            const fixture = new ComponentFixture(Cmpt); | 
					
						
							|  |  |  |            const qList = fixture.component.query; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            expect(qList.length).toBe(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            directiveInstances[0].insertTpl(tpl !, {idx: 0, container_idx: 0}, 0); | 
					
						
							|  |  |  |            directiveInstances[1].insertTpl(tpl !, {idx: 0, container_idx: 1}, 0); | 
					
						
							|  |  |  |            fixture.update(); | 
					
						
							|  |  |  |            expect(qList.length).toBe(2); | 
					
						
							|  |  |  |            let qListArr = qList.toArray(); | 
					
						
							|  |  |  |            expect(qListArr[0].nativeElement.getAttribute('id')).toBe('foo_1_0'); | 
					
						
							|  |  |  |            expect(qListArr[1].nativeElement.getAttribute('id')).toBe('foo_0_0'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            directiveInstances[0].remove(); | 
					
						
							|  |  |  |            fixture.update(); | 
					
						
							|  |  |  |            expect(qList.length).toBe(1); | 
					
						
							|  |  |  |            qListArr = qList.toArray(); | 
					
						
							|  |  |  |            expect(qListArr[0].nativeElement.getAttribute('id')).toBe('foo_1_0'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            directiveInstances[1].remove(); | 
					
						
							|  |  |  |            fixture.update(); | 
					
						
							|  |  |  |            expect(qList.length).toBe(0); | 
					
						
							| 
									
										
										
										
											2018-06-01 17:01:24 +02:00
										 |  |  |          }); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // https://stackblitz.com/edit/angular-wpd6gv?file=src%2Fapp%2Fapp.component.ts
 | 
					
						
							|  |  |  |       it('should report results from views inserted in a lifecycle hook', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |         function MyApp_Template_1(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |           if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |             element(0, 'span', ['id', 'from_tpl'], ['foo', '']); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         class MyApp { | 
					
						
							|  |  |  |           show = false; | 
					
						
							|  |  |  |           query: any; | 
					
						
							|  |  |  |           static ngComponentDef = defineComponent({ | 
					
						
							|  |  |  |             type: MyApp, | 
					
						
							|  |  |  |             factory: () => new MyApp(), | 
					
						
							|  |  |  |             selectors: [['my-app']], | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             consts: 5, | 
					
						
							|  |  |  |             vars: 1, | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             /** | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |              * <ng-template #tpl><span #foo id="from_tpl"></span></ng-template> | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |              * <ng-template [ngTemplateOutlet]="show ? tpl : null"></ng-template> | 
					
						
							|  |  |  |              */ | 
					
						
							|  |  |  |             template: (rf: RenderFlags, myApp: MyApp) => { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |                 template( | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                     1, MyApp_Template_1, 2, 0, undefined, undefined, ['tpl', ''], | 
					
						
							| 
									
										
										
										
											2018-09-25 18:44:05 -07:00
										 |  |  |                     templateRefExtractor); | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                 template(3, null, 0, 0, null, [AttributeMarker.SelectOnly, 'ngTemplateOutlet']); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2018-08-14 16:25:01 +02:00
										 |  |  |                 const tplRef = reference(2); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                 elementProperty(3, 'ngTemplateOutlet', bind(myApp.show ? tplRef : null)); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             directives: () => [NgTemplateOutlet], | 
					
						
							|  |  |  |             viewQuery: (rf: RenderFlags, myApp: MyApp) => { | 
					
						
							|  |  |  |               let tmp: any; | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, ['foo'], true); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && | 
					
						
							|  |  |  |                     (myApp.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const fixture = new ComponentFixture(MyApp); | 
					
						
							|  |  |  |         const qList = fixture.component.query; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(qList.length).toBe(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         fixture.component.show = true; | 
					
						
							|  |  |  |         fixture.update(); | 
					
						
							|  |  |  |         expect(qList.length).toBe(1); | 
					
						
							|  |  |  |         expect(qList.first.nativeElement.id).toBe('from_tpl'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         fixture.component.show = false; | 
					
						
							|  |  |  |         fixture.update(); | 
					
						
							|  |  |  |         expect(qList.length).toBe(0); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |     describe('JS blocks', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should report results in embedded views', () => { | 
					
						
							|  |  |  |         let firstEl; | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * % if (exp) { | 
					
						
							|  |  |  |          *    <div #foo></div> | 
					
						
							|  |  |  |          * % } | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren('foo') query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 container(1); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 containerRefreshStart(1); | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |                 { | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                   if (ctx.exp) { | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                     let rf1 = embeddedViewStart(1, 2, 0); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                     { | 
					
						
							|  |  |  |                       if (rf1 & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-07-27 14:56:15 -07:00
										 |  |  |                         element(0, 'div', null, ['foo', '']); | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |                         firstEl = getNativeByIndex(0, getViewData()); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                       } | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     embeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |                   } | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                 containerRefreshEnd(); | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             2, 0, [], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, ['foo'], true); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |         const qList = (cmptInstance.query as any); | 
					
						
							|  |  |  |         expect(qList.length).toBe(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cmptInstance.exp = true; | 
					
						
							|  |  |  |         detectChanges(cmptInstance); | 
					
						
							|  |  |  |         expect(qList.length).toBe(1); | 
					
						
							|  |  |  |         expect(qList.first.nativeElement).toBe(firstEl); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         cmptInstance.exp = false; | 
					
						
							|  |  |  |         detectChanges(cmptInstance); | 
					
						
							|  |  |  |         expect(qList.length).toBe(0); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should add results from embedded views in the correct order - views and elements mix', | 
					
						
							|  |  |  |          () => { | 
					
						
							|  |  |  |            let firstEl, lastEl, viewEl; | 
					
						
							|  |  |  |            /** | 
					
						
							|  |  |  |             * <span #foo></span> | 
					
						
							|  |  |  |             * % if (exp) { | 
					
						
							|  |  |  |             *    <div #foo></div> | 
					
						
							|  |  |  |             * % } | 
					
						
							|  |  |  |             * <span #foo></span> | 
					
						
							|  |  |  |             * class Cmpt { | 
					
						
							|  |  |  |             *  @ViewChildren('foo') query; | 
					
						
							|  |  |  |             * } | 
					
						
							|  |  |  |             */ | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |            const Cmpt = createComponent( | 
					
						
							|  |  |  |                'cmpt', | 
					
						
							|  |  |  |                function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |                  if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-07-27 14:56:15 -07:00
										 |  |  |                    element(1, 'span', null, ['foo', '']); | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |                    firstEl = getNativeByIndex(1, getViewData()); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                    container(3); | 
					
						
							| 
									
										
										
										
											2018-07-27 14:56:15 -07:00
										 |  |  |                    element(4, 'span', null, ['foo', '']); | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |                    lastEl = getNativeByIndex(4, getViewData()); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                  } | 
					
						
							|  |  |  |                  if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                    containerRefreshStart(3); | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |                    { | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                      if (ctx.exp) { | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                        let rf1 = embeddedViewStart(1, 2, 0); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                        { | 
					
						
							|  |  |  |                          if (rf1 & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-07-27 14:56:15 -07:00
										 |  |  |                            element(0, 'div', null, ['foo', '']); | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |                            viewEl = getNativeByIndex(0, getViewData()); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                          } | 
					
						
							|  |  |  |                        } | 
					
						
							|  |  |  |                        embeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |                      } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |                    } | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                    containerRefreshEnd(); | 
					
						
							|  |  |  |                  } | 
					
						
							|  |  |  |                }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                6, 0, [], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |                  if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                    query(0, ['foo'], true); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  |                  } | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                  if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                    let tmp: any; | 
					
						
							|  |  |  |                    queryRefresh(tmp = load<QueryList<any>>(0)) && | 
					
						
							|  |  |  |                        (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |                  } | 
					
						
							|  |  |  |                }); | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |            const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |            const qList = (cmptInstance.query as any); | 
					
						
							|  |  |  |            expect(qList.length).toBe(2); | 
					
						
							|  |  |  |            expect(qList.first.nativeElement).toBe(firstEl); | 
					
						
							|  |  |  |            expect(qList.last.nativeElement).toBe(lastEl); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            cmptInstance.exp = true; | 
					
						
							|  |  |  |            detectChanges(cmptInstance); | 
					
						
							|  |  |  |            expect(qList.length).toBe(3); | 
					
						
							|  |  |  |            expect(qList.toArray()[0].nativeElement).toBe(firstEl); | 
					
						
							|  |  |  |            expect(qList.toArray()[1].nativeElement).toBe(viewEl); | 
					
						
							|  |  |  |            expect(qList.toArray()[2].nativeElement).toBe(lastEl); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |            cmptInstance.exp = false; | 
					
						
							|  |  |  |            detectChanges(cmptInstance); | 
					
						
							|  |  |  |            expect(qList.length).toBe(2); | 
					
						
							|  |  |  |            expect(qList.first.nativeElement).toBe(firstEl); | 
					
						
							|  |  |  |            expect(qList.last.nativeElement).toBe(lastEl); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  |          }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |       it('should add results from embedded views in the correct order - views side by side', () => { | 
					
						
							|  |  |  |         let firstEl, lastEl; | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * % if (exp1) { | 
					
						
							|  |  |  |          *    <div #foo></div> | 
					
						
							|  |  |  |          * % } if (exp2) { | 
					
						
							|  |  |  |          *    <span #foo></span> | 
					
						
							|  |  |  |          * % } | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren('foo') query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 container(1); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 containerRefreshStart(1); | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |                 { | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                   if (ctx.exp1) { | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                     let rf0 = embeddedViewStart(0, 2, 0); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                     { | 
					
						
							|  |  |  |                       if (rf0 & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-07-27 14:56:15 -07:00
										 |  |  |                         element(0, 'div', null, ['foo', '']); | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |                         firstEl = getNativeByIndex(0, getViewData()); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                       } | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     embeddedViewEnd(); | 
					
						
							|  |  |  |                   } | 
					
						
							|  |  |  |                   if (ctx.exp2) { | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                     let rf1 = embeddedViewStart(1, 2, 0); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                     { | 
					
						
							|  |  |  |                       if (rf1 & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-07-27 14:56:15 -07:00
										 |  |  |                         element(0, 'span', null, ['foo', '']); | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |                         lastEl = getNativeByIndex(0, getViewData()); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                       } | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     embeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |                   } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                 containerRefreshEnd(); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             2, 0, [], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, ['foo'], true); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |         const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |         const qList = (cmptInstance.query as any); | 
					
						
							|  |  |  |         expect(qList.length).toBe(0); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |         cmptInstance.exp2 = true; | 
					
						
							|  |  |  |         detectChanges(cmptInstance); | 
					
						
							|  |  |  |         expect(qList.length).toBe(1); | 
					
						
							|  |  |  |         expect(qList.last.nativeElement).toBe(lastEl); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |         cmptInstance.exp1 = true; | 
					
						
							|  |  |  |         detectChanges(cmptInstance); | 
					
						
							|  |  |  |         expect(qList.length).toBe(2); | 
					
						
							|  |  |  |         expect(qList.first.nativeElement).toBe(firstEl); | 
					
						
							|  |  |  |         expect(qList.last.nativeElement).toBe(lastEl); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |       it('should add results from embedded views in the correct order - nested views', () => { | 
					
						
							|  |  |  |         let firstEl, lastEl; | 
					
						
							|  |  |  |         /** | 
					
						
							|  |  |  |          * % if (exp1) { | 
					
						
							|  |  |  |          *    <div #foo></div> | 
					
						
							|  |  |  |          *    % if (exp2) { | 
					
						
							|  |  |  |          *      <span #foo></span> | 
					
						
							|  |  |  |          *    } | 
					
						
							|  |  |  |          * % } | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							|  |  |  |          *  @ViewChildren('foo') query; | 
					
						
							|  |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 container(1); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 containerRefreshStart(1); | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |                 { | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                   if (ctx.exp1) { | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                     let rf0 = embeddedViewStart(0, 3, 0); | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |                     { | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                       if (rf0 & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-07-27 14:56:15 -07:00
										 |  |  |                         element(0, 'div', null, ['foo', '']); | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |                         firstEl = getNativeByIndex(0, getViewData()); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                         container(2); | 
					
						
							|  |  |  |                       } | 
					
						
							|  |  |  |                       if (rf0 & RenderFlags.Update) { | 
					
						
							|  |  |  |                         containerRefreshStart(2); | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |                         { | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                           if (ctx.exp2) { | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                             let rf2 = embeddedViewStart(0, 2, 0); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                             { | 
					
						
							|  |  |  |                               if (rf2) { | 
					
						
							| 
									
										
										
										
											2018-07-27 14:56:15 -07:00
										 |  |  |                                 element(0, 'span', null, ['foo', '']); | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |                                 lastEl = getNativeByIndex(0, getViewData()); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                               } | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                             embeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |                           } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |                         } | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                         containerRefreshEnd(); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |                       } | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  |                     } | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                     embeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  |                   } | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                 containerRefreshEnd(); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             2, 0, [], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, ['foo'], true); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |         const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |         const qList = (cmptInstance.query as any); | 
					
						
							|  |  |  |         expect(qList.length).toBe(0); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |         cmptInstance.exp1 = true; | 
					
						
							|  |  |  |         detectChanges(cmptInstance); | 
					
						
							|  |  |  |         expect(qList.length).toBe(1); | 
					
						
							|  |  |  |         expect(qList.first.nativeElement).toBe(firstEl); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |         cmptInstance.exp2 = true; | 
					
						
							|  |  |  |         detectChanges(cmptInstance); | 
					
						
							|  |  |  |         expect(qList.length).toBe(2); | 
					
						
							|  |  |  |         expect(qList.first.nativeElement).toBe(firstEl); | 
					
						
							|  |  |  |         expect(qList.last.nativeElement).toBe(lastEl); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |       /** | 
					
						
							|  |  |  |        * What is tested here can't be achieved in the Renderer2 as all view queries are deep by | 
					
						
							|  |  |  |        * default and can't be marked as shallow by a user. | 
					
						
							|  |  |  |        */ | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |       it('should support combination of deep and shallow queries', () => { | 
					
						
							|  |  |  |         /** | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |          * % if (exp) { "> | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |          *   <div #foo> | 
					
						
							|  |  |  |          *     <div #foo></div> | 
					
						
							|  |  |  |          *   </div> | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |          * % } | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |          * <span #foo></span> | 
					
						
							|  |  |  |          * class Cmpt { | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |          *  @ViewChildren('foo') deep; | 
					
						
							|  |  |  |          *  @ViewChildren('foo') shallow; | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |          * } | 
					
						
							|  |  |  |          */ | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |         const Cmpt = createComponent( | 
					
						
							|  |  |  |             'cmpt', | 
					
						
							|  |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 container(2); | 
					
						
							| 
									
										
										
										
											2018-07-27 14:28:22 -07:00
										 |  |  |                 element(3, 'span', null, ['foo', '']); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 containerRefreshStart(2); | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |                 { | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                   if (ctx.exp) { | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                     let rf0 = embeddedViewStart(0, 4, 0); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                     { | 
					
						
							|  |  |  |                       if (rf0 & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |                         elementStart(0, 'div', null, ['foo', '']); | 
					
						
							|  |  |  |                         { element(2, 'div', null, ['foo', '']); } | 
					
						
							|  |  |  |                         elementEnd(); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                       } | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     embeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |                   } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |                 containerRefreshEnd(); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             5, 0, [], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |                 query(0, ['foo'], true); | 
					
						
							|  |  |  |                 query(1, ['foo'], false); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 let tmp: any; | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.deep = tmp as QueryList<any>); | 
					
						
							|  |  |  |                 queryRefresh(tmp = load<QueryList<any>>(1)) && | 
					
						
							|  |  |  |                     (ctx.shallow = tmp as QueryList<any>); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |         const cmptInstance = renderComponent(Cmpt); | 
					
						
							|  |  |  |         const deep = (cmptInstance.deep as any); | 
					
						
							|  |  |  |         const shallow = (cmptInstance.shallow as any); | 
					
						
							|  |  |  |         expect(deep.length).toBe(1); | 
					
						
							|  |  |  |         expect(shallow.length).toBe(1); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  |         cmptInstance.exp = true; | 
					
						
							|  |  |  |         detectChanges(cmptInstance); | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |         expect(deep.length).toBe(3); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // embedded % if blocks should behave the same way as *ngIf, namely they
 | 
					
						
							|  |  |  |         // should match shallow queries on the first level of elements underneath
 | 
					
						
							|  |  |  |         // the embedded view boundary.
 | 
					
						
							|  |  |  |         expect(shallow.length).toBe(2); | 
					
						
							| 
									
										
										
										
											2018-05-28 11:57:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         cmptInstance.exp = false; | 
					
						
							|  |  |  |         detectChanges(cmptInstance); | 
					
						
							|  |  |  |         expect(deep.length).toBe(1); | 
					
						
							|  |  |  |         expect(shallow.length).toBe(1); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-01-29 16:06:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe('observable interface', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should allow observing changes to query list', () => { | 
					
						
							|  |  |  |       const queryList = new QueryList(); | 
					
						
							|  |  |  |       let changes = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       queryList.changes.subscribe({ | 
					
						
							|  |  |  |         next: (arg) => { | 
					
						
							|  |  |  |           changes += 1; | 
					
						
							|  |  |  |           expect(arg).toBe(queryList); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // initial refresh, the query should be dirty
 | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |       queryRefresh(queryList); | 
					
						
							| 
									
										
										
										
											2018-01-29 16:06:31 +01:00
										 |  |  |       expect(changes).toBe(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // refresh without setting dirty - no emit
 | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |       queryRefresh(queryList); | 
					
						
							| 
									
										
										
										
											2018-01-29 16:06:31 +01:00
										 |  |  |       expect(changes).toBe(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // refresh with setting dirty - emit
 | 
					
						
							|  |  |  |       queryList.setDirty(); | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |       queryRefresh(queryList); | 
					
						
							| 
									
										
										
										
											2018-01-29 16:06:31 +01:00
										 |  |  |       expect(changes).toBe(2); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-05-31 15:45:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe('queryList', () => { | 
					
						
							|  |  |  |     it('should be destroyed when the containing view is destroyed', () => { | 
					
						
							|  |  |  |       let queryInstance: QueryList<any>; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |       const SimpleComponentWithQuery = createComponent( | 
					
						
							|  |  |  |           'some-component-with-query', | 
					
						
							|  |  |  |           function(rf: RenderFlags, ctx: any) { | 
					
						
							| 
									
										
										
										
											2018-05-31 15:45:46 +02:00
										 |  |  |             if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-07-27 14:28:22 -07:00
										 |  |  |               element(1, 'div', null, ['foo', '']); | 
					
						
							| 
									
										
										
										
											2018-05-31 15:45:46 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |           }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |           2, 0, [], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |           function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |             if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |               query(0, ['foo'], false); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2018-05-31 15:45:46 +02:00
										 |  |  |             if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               let tmp: any; | 
					
						
							| 
									
										
										
										
											2018-05-31 15:45:46 +02:00
										 |  |  |               queryRefresh(tmp = load<QueryList<any>>(0)) && | 
					
						
							|  |  |  |                   (ctx.query = queryInstance = tmp as QueryList<any>); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       function createTemplate() { container(0); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       function updateTemplate() { | 
					
						
							|  |  |  |         containerRefreshStart(0); | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           if (condition) { | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             let rf1 = embeddedViewStart(1, 1, 0); | 
					
						
							| 
									
										
										
										
											2018-05-31 15:45:46 +02:00
										 |  |  |             { | 
					
						
							|  |  |  |               if (rf1 & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-07-27 14:28:22 -07:00
										 |  |  |                 element(0, 'some-component-with-query'); | 
					
						
							| 
									
										
										
										
											2018-05-31 15:45:46 +02:00
										 |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             embeddedViewEnd(); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         containerRefreshEnd(); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       /** | 
					
						
							|  |  |  |        * % if (condition) { | 
					
						
							|  |  |  |        *   <some-component-with-query></some-component-with-query> | 
					
						
							|  |  |  |        * %} | 
					
						
							|  |  |  |        */ | 
					
						
							|  |  |  |       let condition = true; | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |       const t = | 
					
						
							|  |  |  |           new TemplateFixture(createTemplate, updateTemplate, 1, 0, [SimpleComponentWithQuery]); | 
					
						
							| 
									
										
										
										
											2018-05-31 15:45:46 +02:00
										 |  |  |       expect(t.html).toEqual('<some-component-with-query><div></div></some-component-with-query>'); | 
					
						
							|  |  |  |       expect((queryInstance !.changes as EventEmitter<any>).closed).toBeFalsy(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       condition = false; | 
					
						
							|  |  |  |       t.update(); | 
					
						
							|  |  |  |       expect(t.html).toEqual(''); | 
					
						
							|  |  |  |       expect((queryInstance !.changes as EventEmitter<any>).closed).toBeTruthy(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-06-14 15:45:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-09 14:07:47 -07:00
										 |  |  |   it('should restore queries if view changes', () => { | 
					
						
							|  |  |  |     class SomeDir { | 
					
						
							|  |  |  |       constructor(public vcr: ViewContainerRef, public temp: TemplateRef<any>) { | 
					
						
							|  |  |  |         this.vcr.createEmbeddedView(this.temp); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       static ngDirectiveDef = defineDirective({ | 
					
						
							|  |  |  |         type: SomeDir, | 
					
						
							|  |  |  |         selectors: [['', 'someDir', '']], | 
					
						
							| 
									
										
										
										
											2018-09-21 18:38:13 -07:00
										 |  |  |         factory: () => new SomeDir( | 
					
						
							|  |  |  |                      directiveInject(ViewContainerRef as any), directiveInject(TemplateRef as any)) | 
					
						
							| 
									
										
										
										
											2018-08-09 14:07:47 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-15 18:37:03 -07:00
										 |  |  |     function AppComponent_Template_1(rf: RenderFlags, ctx: any) { | 
					
						
							| 
									
										
										
										
											2018-08-09 14:07:47 -07:00
										 |  |  |       if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |         element(0, 'div'); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * <div *someDir></div> | 
					
						
							|  |  |  |      * <div #foo></div> | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     const AppComponent = createComponent( | 
					
						
							|  |  |  |         'app', | 
					
						
							|  |  |  |         function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |           if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             template( | 
					
						
							|  |  |  |                 1, AppComponent_Template_1, 1, 0, null, [AttributeMarker.SelectOnly, 'someDir']); | 
					
						
							| 
									
										
										
										
											2018-08-09 14:07:47 -07:00
										 |  |  |             element(2, 'div', null, ['foo', '']); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |         4, 0, [SomeDir], [], | 
					
						
							| 
									
										
										
										
											2018-08-09 14:07:47 -07:00
										 |  |  |         function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |           if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |             query(0, ['foo'], true); | 
					
						
							| 
									
										
										
										
											2018-08-09 14:07:47 -07:00
										 |  |  |           } | 
					
						
							|  |  |  |           if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |             let tmp: any; | 
					
						
							|  |  |  |             queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.query = tmp as QueryList<any>); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const fixture = new ComponentFixture(AppComponent); | 
					
						
							|  |  |  |     expect(fixture.component.query.length).toBe(1); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-14 15:45:21 +02:00
										 |  |  |   describe('content', () => { | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |     let withContentInstance: WithContentDirective|null; | 
					
						
							|  |  |  |     let shallowCompInstance: ShallowComp|null; | 
					
						
							| 
									
										
										
										
											2018-06-14 15:45:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |     beforeEach(() => { | 
					
						
							|  |  |  |       withContentInstance = null; | 
					
						
							|  |  |  |       shallowCompInstance = null; | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-08-02 14:27:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |     class WithContentDirective { | 
					
						
							|  |  |  |       // @ContentChildren('foo')
 | 
					
						
							|  |  |  |       foos !: QueryList<ElementRef>; | 
					
						
							|  |  |  |       contentInitQuerySnapshot = 0; | 
					
						
							|  |  |  |       contentCheckedQuerySnapshot = 0; | 
					
						
							| 
									
										
										
										
											2018-08-02 14:27:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |       ngAfterContentInit() { this.contentInitQuerySnapshot = this.foos ? this.foos.length : 0; } | 
					
						
							| 
									
										
										
										
											2018-07-10 10:43:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |       ngAfterContentChecked() { | 
					
						
							|  |  |  |         this.contentCheckedQuerySnapshot = this.foos ? this.foos.length : 0; | 
					
						
							| 
									
										
										
										
											2018-07-10 10:43:07 +02:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |       static ngComponentDef = defineDirective({ | 
					
						
							|  |  |  |         type: WithContentDirective, | 
					
						
							|  |  |  |         selectors: [['', 'with-content', '']], | 
					
						
							|  |  |  |         factory: () => new WithContentDirective(), | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |         contentQueries: | 
					
						
							|  |  |  |             (dirIndex) => { registerContentQuery(query(null, ['foo'], true), dirIndex); }, | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |         contentQueriesRefresh: (dirIndex: number, queryStartIdx: number) => { | 
					
						
							|  |  |  |           let tmp: any; | 
					
						
							| 
									
										
										
										
											2018-10-08 16:04:46 -07:00
										 |  |  |           withContentInstance = load<WithContentDirective>(dirIndex); | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |           queryRefresh(tmp = loadQueryList<ElementRef>(queryStartIdx)) && | 
					
						
							|  |  |  |               (withContentInstance.foos = tmp); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class ShallowComp { | 
					
						
							|  |  |  |       // @ContentChildren('foo', {descendants: false})
 | 
					
						
							|  |  |  |       foos !: QueryList<ElementRef>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       static ngComponentDef = defineComponent({ | 
					
						
							|  |  |  |         type: ShallowComp, | 
					
						
							|  |  |  |         selectors: [['shallow-comp']], | 
					
						
							|  |  |  |         factory: () => new ShallowComp(), | 
					
						
							|  |  |  |         template: function(rf: RenderFlags, ctx: any) {}, | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |         consts: 0, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |         vars: 0, | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |         contentQueries: | 
					
						
							|  |  |  |             (dirIndex) => { registerContentQuery(query(null, ['foo'], false), dirIndex); }, | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |         contentQueriesRefresh: (dirIndex: number, queryStartIdx: number) => { | 
					
						
							|  |  |  |           let tmp: any; | 
					
						
							| 
									
										
										
										
											2018-10-08 16:04:46 -07:00
										 |  |  |           shallowCompInstance = load<ShallowComp>(dirIndex); | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |           queryRefresh(tmp = loadQueryList<ElementRef>(queryStartIdx)) && | 
					
						
							|  |  |  |               (shallowCompInstance.foos = tmp); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should support content queries for directives', () => { | 
					
						
							| 
									
										
										
										
											2018-07-10 10:43:07 +02:00
										 |  |  |       /** | 
					
						
							|  |  |  |        * <div with-content> | 
					
						
							|  |  |  |        *   <span #foo></span> | 
					
						
							|  |  |  |        * </div> | 
					
						
							|  |  |  |        */ | 
					
						
							|  |  |  |       const AppComponent = createComponent('app-component', function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |           elementStart(0, 'div', [AttributeMarker.SelectOnly, 'with-content']); | 
					
						
							|  |  |  |           { element(1, 'span', null, ['foo', '']); } | 
					
						
							|  |  |  |           elementEnd(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |       }, 3, 0, [WithContentDirective]); | 
					
						
							| 
									
										
										
										
											2018-07-10 10:43:07 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const fixture = new ComponentFixture(AppComponent); | 
					
						
							| 
									
										
										
										
											2018-08-02 14:27:36 -07:00
										 |  |  |       expect(withContentInstance !.foos.length) | 
					
						
							|  |  |  |           .toBe(1, `Expected content query to match <span #foo>.`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(withContentInstance !.contentInitQuerySnapshot) | 
					
						
							|  |  |  |           .toBe( | 
					
						
							|  |  |  |               1, | 
					
						
							|  |  |  |               `Expected content query results to be available when ngAfterContentInit was called.`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(withContentInstance !.contentCheckedQuerySnapshot) | 
					
						
							|  |  |  |           .toBe( | 
					
						
							|  |  |  |               1, | 
					
						
							|  |  |  |               `Expected content query results to be available when ngAfterContentChecked was called.`); | 
					
						
							| 
									
										
										
										
											2018-07-10 10:43:07 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |     it('should support content queries for directives within repeated embedded views', () => { | 
					
						
							|  |  |  |       /** | 
					
						
							|  |  |  |        * % for (let i = 0; i < 3; i++) { | 
					
						
							|  |  |  |        *   <div with-content> | 
					
						
							|  |  |  |        *     <span #foo></span> | 
					
						
							|  |  |  |        *   </div> | 
					
						
							|  |  |  |        * % } | 
					
						
							|  |  |  |        */ | 
					
						
							|  |  |  |       const AppComponent = createComponent('app-component', function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |           container(0); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |           containerRefreshStart(0); | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             for (let i = 0; i < 3; i++) { | 
					
						
							|  |  |  |               let rf = embeddedViewStart(1, 3, 0); | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                 elementStart(0, 'div', [AttributeMarker.SelectOnly, 'with-content']); | 
					
						
							|  |  |  |                 { element(1, 'span', null, ['foo', '']); } | 
					
						
							|  |  |  |                 elementEnd(); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |               embeddedViewEnd(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           containerRefreshEnd(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }, 1, 0, [WithContentDirective]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const fixture = new ComponentFixture(AppComponent); | 
					
						
							|  |  |  |       expect(withContentInstance !.foos.length) | 
					
						
							|  |  |  |           .toBe(1, `Expected content query to match <span #foo>.`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(withContentInstance !.contentInitQuerySnapshot) | 
					
						
							|  |  |  |           .toBe( | 
					
						
							|  |  |  |               1, | 
					
						
							|  |  |  |               `Expected content query results to be available when ngAfterContentInit was called.`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(withContentInstance !.contentCheckedQuerySnapshot) | 
					
						
							|  |  |  |           .toBe( | 
					
						
							|  |  |  |               1, | 
					
						
							|  |  |  |               `Expected content query results to be available when ngAfterContentChecked was called.`); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |     it('should support content query matches on directive hosts', () => { | 
					
						
							|  |  |  |       /** | 
					
						
							|  |  |  |        * <div with-content #foo> | 
					
						
							|  |  |  |        * </div> | 
					
						
							|  |  |  |        */ | 
					
						
							|  |  |  |       const AppComponent = createComponent('app-component', function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |           element(0, 'div', ['with-content', ''], ['foo', '']); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |       }, 2, 0, [WithContentDirective]); | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const fixture = new ComponentFixture(AppComponent); | 
					
						
							|  |  |  |       expect(withContentInstance !.foos.length) | 
					
						
							|  |  |  |           .toBe(1, `Expected content query to match <div with-content #foo>.`); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('should match shallow content queries in views inserted / removed by ngIf', () => { | 
					
						
							|  |  |  |       function IfTemplate(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |           element(0, 'div', null, ['foo', '']); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-06-14 15:45:21 +02:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       /** | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |        * <shallow-comp> | 
					
						
							|  |  |  |        *    <div *ngIf="showing" #foo></div> | 
					
						
							|  |  |  |        * </shallow-comp> | 
					
						
							|  |  |  |        */ | 
					
						
							|  |  |  |       const AppComponent = createComponent('app-component', function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |         if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |           elementStart(0, 'shallow-comp'); | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |           { template(1, IfTemplate, 2, 0, null, [AttributeMarker.SelectOnly, 'ngIf', '']); } | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |           elementEnd(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |           elementProperty(1, 'ngIf', bind(ctx.showing)); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |       }, 2, 1, [ShallowComp, NgIf]); | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const fixture = new ComponentFixture(AppComponent); | 
					
						
							|  |  |  |       const qList = shallowCompInstance !.foos; | 
					
						
							|  |  |  |       expect(qList.length).toBe(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       fixture.component.showing = true; | 
					
						
							|  |  |  |       fixture.update(); | 
					
						
							|  |  |  |       expect(qList.length).toBe(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       fixture.component.showing = false; | 
					
						
							|  |  |  |       fixture.update(); | 
					
						
							|  |  |  |       expect(qList.length).toBe(0); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://stackblitz.com/edit/angular-wlenwd?file=src%2Fapp%2Fapp.component.ts
 | 
					
						
							|  |  |  |     it('should support view and content queries matching the same element', () => { | 
					
						
							|  |  |  |       /** | 
					
						
							|  |  |  |        * <div with-content> | 
					
						
							| 
									
										
										
										
											2018-06-14 15:45:21 +02:00
										 |  |  |        *   <div #foo></div> | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |        * </div> | 
					
						
							| 
									
										
										
										
											2018-06-14 15:45:21 +02:00
										 |  |  |        * <div id="after" #bar></div> | 
					
						
							|  |  |  |        * class Cmpt { | 
					
						
							|  |  |  |        *  @ViewChildren('foo, bar') foos; | 
					
						
							|  |  |  |        * } | 
					
						
							|  |  |  |        */ | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |       const AppComponent = createComponent( | 
					
						
							|  |  |  |           'app-component', | 
					
						
							|  |  |  |           function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |             if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |               elementStart(1, 'div', ['with-content', '']); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |               { element(2, 'div', null, ['foo', '']); } | 
					
						
							|  |  |  |               elementEnd(); | 
					
						
							|  |  |  |               element(4, 'div', ['id', 'after'], ['bar', '']); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |           6, 0, [WithContentDirective], [], | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |           function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |             if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |               query(0, ['foo', 'bar'], true); | 
					
						
							| 
									
										
										
										
											2018-06-19 17:58:42 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |             if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |               let tmp: any; | 
					
						
							|  |  |  |               queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.foos = tmp as QueryList<any>); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           }); | 
					
						
							| 
									
										
										
										
											2018-06-14 15:45:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const fixture = new ComponentFixture(AppComponent); | 
					
						
							|  |  |  |       const viewQList = fixture.component.foos; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(viewQList.length).toBe(2); | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |       expect(withContentInstance !.foos.length).toBe(1); | 
					
						
							|  |  |  |       expect(viewQList.first.nativeElement).toBe(withContentInstance !.foos.first.nativeElement); | 
					
						
							| 
									
										
										
										
											2018-06-14 15:45:21 +02:00
										 |  |  |       expect(viewQList.last.nativeElement.id).toBe('after'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |     it('should not report deep content query matches found above content children', () => { | 
					
						
							|  |  |  |       /** | 
					
						
							|  |  |  |        * <div with-content> | 
					
						
							|  |  |  |        *   <div #foo id="yes"></div>    <-- should match content query | 
					
						
							|  |  |  |        * </div> | 
					
						
							|  |  |  |        * <div #foo></div>              <-- should not match content query | 
					
						
							|  |  |  |        * class AppComponent { | 
					
						
							|  |  |  |        *  @ViewChildren('bar') bars: QueryList<ElementRef>; | 
					
						
							|  |  |  |        * } | 
					
						
							|  |  |  |        */ | 
					
						
							|  |  |  |       const AppComponent = createComponent( | 
					
						
							|  |  |  |           'app-component', | 
					
						
							|  |  |  |           function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |             if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |               elementStart(1, 'div', ['with-content', '']); | 
					
						
							|  |  |  |               { element(2, 'div', ['id', 'yes'], ['foo', '']); } | 
					
						
							|  |  |  |               elementEnd(); | 
					
						
							|  |  |  |               element(4, 'div', null, ['foo', '']); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |           6, 0, [WithContentDirective], [], | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |           function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |             if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-09-28 17:20:43 -07:00
										 |  |  |               query(0, ['bar'], true); | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |             } | 
					
						
							|  |  |  |             if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |               let tmp: any; | 
					
						
							|  |  |  |               queryRefresh(tmp = load<QueryList<any>>(0)) && (ctx.bars = tmp as QueryList<any>); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const fixture = new ComponentFixture(AppComponent); | 
					
						
							|  |  |  |       expect(withContentInstance !.foos.length).toBe(1); | 
					
						
							|  |  |  |       expect(withContentInstance !.foos.first.nativeElement.id).toEqual('yes'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-06-26 14:19:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |     it('should report results to appropriate queries where deep content queries are nested', () => { | 
					
						
							| 
									
										
										
										
											2018-06-26 14:19:00 +02:00
										 |  |  |       class QueryDirective { | 
					
						
							|  |  |  |         fooBars: any; | 
					
						
							|  |  |  |         static ngDirectiveDef = defineDirective({ | 
					
						
							|  |  |  |           type: QueryDirective, | 
					
						
							|  |  |  |           selectors: [['', 'query', '']], | 
					
						
							|  |  |  |           exportAs: 'query', | 
					
						
							| 
									
										
										
										
											2018-07-10 10:43:07 +02:00
										 |  |  |           factory: () => new QueryDirective(), | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |           contentQueries: (dirIndex) => { | 
					
						
							| 
									
										
										
										
											2018-06-26 14:19:00 +02:00
										 |  |  |             // @ContentChildren('foo, bar, baz', {descendants: true}) fooBars:
 | 
					
						
							|  |  |  |             // QueryList<ElementRef>;
 | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |             registerContentQuery(query(null, ['foo', 'bar', 'baz'], true), dirIndex); | 
					
						
							| 
									
										
										
										
											2018-06-26 14:19:00 +02:00
										 |  |  |           }, | 
					
						
							| 
									
										
										
										
											2018-07-10 10:43:07 +02:00
										 |  |  |           contentQueriesRefresh: (dirIndex: number, queryStartIdx: number) => { | 
					
						
							| 
									
										
										
										
											2018-06-26 14:19:00 +02:00
										 |  |  |             let tmp: any; | 
					
						
							| 
									
										
										
										
											2018-10-08 16:04:46 -07:00
										 |  |  |             const instance = load<QueryDirective>(dirIndex); | 
					
						
							| 
									
										
										
										
											2018-07-10 10:43:07 +02:00
										 |  |  |             queryRefresh(tmp = loadQueryList<ElementRef>(queryStartIdx)) && | 
					
						
							|  |  |  |                 (instance.fooBars = tmp); | 
					
						
							| 
									
										
										
										
											2018-06-26 14:19:00 +02:00
										 |  |  |           }, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       let outInstance: QueryDirective; | 
					
						
							|  |  |  |       let inInstance: QueryDirective; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const AppComponent = createComponent( | 
					
						
							|  |  |  |           'app-component', | 
					
						
							|  |  |  |           /** | 
					
						
							|  |  |  |            * <div query #out="query"> | 
					
						
							|  |  |  |            *   <span #foo></span> | 
					
						
							|  |  |  |            *   <div query #in="query"> | 
					
						
							|  |  |  |            *     <span #bar></span> | 
					
						
							|  |  |  |            *   </div> | 
					
						
							|  |  |  |            *   <span #baz></span> | 
					
						
							|  |  |  |            * </div> | 
					
						
							|  |  |  |            */ | 
					
						
							|  |  |  |           function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |             if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |               elementStart(0, 'div', [AttributeMarker.SelectOnly, 'query'], ['out', 'query']); | 
					
						
							|  |  |  |               { | 
					
						
							|  |  |  |                 element(2, 'span', ['id', 'foo'], ['foo', '']); | 
					
						
							|  |  |  |                 elementStart(4, 'div', [AttributeMarker.SelectOnly, 'query'], ['in', 'query']); | 
					
						
							|  |  |  |                 { element(6, 'span', ['id', 'bar'], ['bar', '']); } | 
					
						
							|  |  |  |                 elementEnd(); | 
					
						
							|  |  |  |                 element(8, 'span', ['id', 'baz'], ['baz', '']); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |               elementEnd(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2018-07-10 10:43:07 +02:00
										 |  |  |               outInstance = load<QueryDirective>(1); | 
					
						
							|  |  |  |               inInstance = load<QueryDirective>(5); | 
					
						
							| 
									
										
										
										
											2018-06-26 14:19:00 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |           10, 0, [QueryDirective]); | 
					
						
							| 
									
										
										
										
											2018-06-26 14:19:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const fixture = new ComponentFixture(AppComponent); | 
					
						
							|  |  |  |       expect(outInstance !.fooBars.length).toBe(3); | 
					
						
							|  |  |  |       expect(inInstance !.fooBars.length).toBe(1); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('should support nested shallow content queries ', () => { | 
					
						
							|  |  |  |       let outInstance: QueryDirective; | 
					
						
							|  |  |  |       let inInstance: QueryDirective; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       class QueryDirective { | 
					
						
							|  |  |  |         fooBars: any; | 
					
						
							|  |  |  |         static ngDirectiveDef = defineDirective({ | 
					
						
							|  |  |  |           type: QueryDirective, | 
					
						
							|  |  |  |           selectors: [['', 'query', '']], | 
					
						
							|  |  |  |           exportAs: 'query', | 
					
						
							|  |  |  |           factory: () => new QueryDirective(), | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |           contentQueries: (dirIndex) => { | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |             // @ContentChildren('foo, bar, baz', {descendants: true}) fooBars:
 | 
					
						
							|  |  |  |             // QueryList<ElementRef>;
 | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |             registerContentQuery(query(null, ['foo'], false), dirIndex); | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |           }, | 
					
						
							|  |  |  |           contentQueriesRefresh: (dirIndex: number, queryStartIdx: number) => { | 
					
						
							|  |  |  |             let tmp: any; | 
					
						
							| 
									
										
										
										
											2018-10-08 16:04:46 -07:00
										 |  |  |             const instance = load<QueryDirective>(dirIndex); | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |             queryRefresh(tmp = loadQueryList<ElementRef>(queryStartIdx)) && | 
					
						
							|  |  |  |                 (instance.fooBars = tmp); | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const AppComponent = createComponent( | 
					
						
							|  |  |  |           'app-component', | 
					
						
							|  |  |  |           /** | 
					
						
							|  |  |  |            * <div query #out="query"> | 
					
						
							|  |  |  |            *   <div query #in="query" #foo> | 
					
						
							|  |  |  |            *     <span #foo></span> | 
					
						
							|  |  |  |            *   </div> | 
					
						
							|  |  |  |            * </div> | 
					
						
							|  |  |  |            */ | 
					
						
							|  |  |  |           function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |             if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |               elementStart(0, 'div', ['query', ''], ['out', 'query']); | 
					
						
							|  |  |  |               { | 
					
						
							|  |  |  |                 elementStart(2, 'div', ['query', ''], ['in', 'query', 'foo', '']); | 
					
						
							|  |  |  |                 { element(5, 'span', ['id', 'bar'], ['foo', '']); } | 
					
						
							|  |  |  |                 elementEnd(); | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |               elementEnd(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |               outInstance = load<QueryDirective>(1); | 
					
						
							|  |  |  |               inInstance = load<QueryDirective>(3); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |           7, 0, [QueryDirective]); | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const fixture = new ComponentFixture(AppComponent); | 
					
						
							|  |  |  |       expect(outInstance !.fooBars.length).toBe(1); | 
					
						
							|  |  |  |       expect(inInstance !.fooBars.length).toBe(2); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-26 14:19:00 +02:00
										 |  |  |     it('should respect shallow flag on content queries when mixing deep and shallow queries', | 
					
						
							|  |  |  |        () => { | 
					
						
							|  |  |  |          class ShallowQueryDirective { | 
					
						
							|  |  |  |            foos: any; | 
					
						
							|  |  |  |            static ngDirectiveDef = defineDirective({ | 
					
						
							|  |  |  |              type: ShallowQueryDirective, | 
					
						
							|  |  |  |              selectors: [['', 'shallow-query', '']], | 
					
						
							|  |  |  |              exportAs: 'shallow-query', | 
					
						
							| 
									
										
										
										
											2018-07-10 10:43:07 +02:00
										 |  |  |              factory: () => new ShallowQueryDirective(), | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |              contentQueries: (dirIndex) => { | 
					
						
							| 
									
										
										
										
											2018-07-10 10:43:07 +02:00
										 |  |  |                // @ContentChildren('foo', {descendants: false}) foos: QueryList<ElementRef>;
 | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |                registerContentQuery(query(null, ['foo'], false), dirIndex); | 
					
						
							| 
									
										
										
										
											2018-06-26 14:19:00 +02:00
										 |  |  |              }, | 
					
						
							| 
									
										
										
										
											2018-07-10 10:43:07 +02:00
										 |  |  |              contentQueriesRefresh: (dirIndex: number, queryStartIdx: number) => { | 
					
						
							| 
									
										
										
										
											2018-06-26 14:19:00 +02:00
										 |  |  |                let tmp: any; | 
					
						
							| 
									
										
										
										
											2018-10-08 16:04:46 -07:00
										 |  |  |                const instance = load<ShallowQueryDirective>(dirIndex); | 
					
						
							| 
									
										
										
										
											2018-07-10 10:43:07 +02:00
										 |  |  |                queryRefresh(tmp = loadQueryList<ElementRef>(queryStartIdx)) && | 
					
						
							|  |  |  |                    (instance.foos = tmp); | 
					
						
							| 
									
										
										
										
											2018-06-26 14:19:00 +02:00
										 |  |  |              }, | 
					
						
							|  |  |  |            }); | 
					
						
							|  |  |  |          } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          class DeepQueryDirective { | 
					
						
							|  |  |  |            foos: any; | 
					
						
							|  |  |  |            static ngDirectiveDef = defineDirective({ | 
					
						
							|  |  |  |              type: DeepQueryDirective, | 
					
						
							|  |  |  |              selectors: [['', 'deep-query', '']], | 
					
						
							|  |  |  |              exportAs: 'deep-query', | 
					
						
							| 
									
										
										
										
											2018-07-10 10:43:07 +02:00
										 |  |  |              factory: () => new DeepQueryDirective(), | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |              contentQueries: (dirIndex) => { | 
					
						
							| 
									
										
										
										
											2018-07-10 10:43:07 +02:00
										 |  |  |                // @ContentChildren('foo', {descendants: false}) foos: QueryList<ElementRef>;
 | 
					
						
							| 
									
										
										
										
											2018-10-18 09:23:18 +02:00
										 |  |  |                registerContentQuery(query(null, ['foo'], true), dirIndex); | 
					
						
							| 
									
										
										
										
											2018-06-26 14:19:00 +02:00
										 |  |  |              }, | 
					
						
							| 
									
										
										
										
											2018-07-10 10:43:07 +02:00
										 |  |  |              contentQueriesRefresh: (dirIndex: number, queryStartIdx: number) => { | 
					
						
							| 
									
										
										
										
											2018-06-26 14:19:00 +02:00
										 |  |  |                let tmp: any; | 
					
						
							| 
									
										
										
										
											2018-10-08 16:04:46 -07:00
										 |  |  |                const instance = load<DeepQueryDirective>(dirIndex); | 
					
						
							| 
									
										
										
										
											2018-07-10 10:43:07 +02:00
										 |  |  |                queryRefresh(tmp = loadQueryList<ElementRef>(queryStartIdx)) && | 
					
						
							|  |  |  |                    (instance.foos = tmp); | 
					
						
							| 
									
										
										
										
											2018-06-26 14:19:00 +02:00
										 |  |  |              }, | 
					
						
							|  |  |  |            }); | 
					
						
							|  |  |  |          } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          let shallowInstance: ShallowQueryDirective; | 
					
						
							|  |  |  |          let deepInstance: DeepQueryDirective; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          const AppComponent = createComponent( | 
					
						
							|  |  |  |              'app-component', | 
					
						
							|  |  |  |              /** | 
					
						
							|  |  |  |               * <div shallow-query #shallow="shallow-query" deep-query #deep="deep-query"> | 
					
						
							|  |  |  |                *   <span #foo></span> | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |               *    <div> | 
					
						
							|  |  |  |               *        <span #foo></span> | 
					
						
							|  |  |  |               *    </div> | 
					
						
							| 
									
										
										
										
											2018-06-26 14:19:00 +02:00
										 |  |  |               * </div> | 
					
						
							|  |  |  |               */ | 
					
						
							|  |  |  |              function(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |                if (rf & RenderFlags.Create) { | 
					
						
							|  |  |  |                  elementStart( | 
					
						
							|  |  |  |                      0, 'div', [AttributeMarker.SelectOnly, 'shallow-query', 'deep-query'], | 
					
						
							|  |  |  |                      ['shallow', 'shallow-query', 'deep', 'deep-query']); | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |                  { | 
					
						
							|  |  |  |                    element(3, 'span', null, ['foo', '']); | 
					
						
							|  |  |  |                    elementStart(5, 'div'); | 
					
						
							|  |  |  |                    { element(6, 'span', null, ['foo', '']); } | 
					
						
							|  |  |  |                    elementEnd(); | 
					
						
							|  |  |  |                  } | 
					
						
							| 
									
										
										
										
											2018-06-26 14:19:00 +02:00
										 |  |  |                  elementEnd(); | 
					
						
							|  |  |  |                } | 
					
						
							|  |  |  |                if (rf & RenderFlags.Update) { | 
					
						
							| 
									
										
										
										
											2018-07-10 10:43:07 +02:00
										 |  |  |                  shallowInstance = load<ShallowQueryDirective>(1); | 
					
						
							|  |  |  |                  deepInstance = load<DeepQueryDirective>(2); | 
					
						
							| 
									
										
										
										
											2018-06-26 14:19:00 +02:00
										 |  |  |                } | 
					
						
							|  |  |  |              }, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |              8, 0, [ShallowQueryDirective, DeepQueryDirective]); | 
					
						
							| 
									
										
										
										
											2018-06-26 14:19:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |          const fixture = new ComponentFixture(AppComponent); | 
					
						
							|  |  |  |          expect(shallowInstance !.foos.length).toBe(1); | 
					
						
							| 
									
										
										
										
											2018-08-09 10:00:07 -07:00
										 |  |  |          expect(deepInstance !.foos.length).toBe(2); | 
					
						
							| 
									
										
										
										
											2018-06-26 14:19:00 +02:00
										 |  |  |        }); | 
					
						
							| 
									
										
										
										
											2018-06-14 15:45:21 +02:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | }); |