forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_container_ref_spec.ts
741 lines (643 loc) · 26.2 KB
/
view_container_ref_spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
/**
* @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
*/
import {Component, Directive, TemplateRef, ViewContainerRef} from '../../src/core';
import {getOrCreateNodeInjectorForNode, getOrCreateTemplateRef} from '../../src/render3/di';
import {defineComponent, defineDirective, injectTemplateRef, injectViewContainerRef} from '../../src/render3/index';
import {bind, container, containerRefreshEnd, containerRefreshStart, elementEnd, elementProperty, elementStart, embeddedViewEnd, embeddedViewStart, interpolation1, load, loadDirective, projection, projectionDef, text, textBinding} from '../../src/render3/instructions';
import {RenderFlags} from '../../src/render3/interfaces/definition';
import {ComponentFixture, TemplateFixture} from './render_util';
describe('ViewContainerRef', () => {
let directiveInstance: DirectiveWithVCRef|null;
beforeEach(() => { directiveInstance = null; });
class DirectiveWithVCRef {
static ngDirectiveDef = defineDirective({
type: DirectiveWithVCRef,
selectors: [['', 'vcref', '']],
factory: () => directiveInstance = new DirectiveWithVCRef(injectViewContainerRef()),
inputs: {tplRef: 'tplRef'}
});
tplRef: TemplateRef<{}>;
// injecting a ViewContainerRef to create a dynamic container in which embedded views will be
// created
constructor(public vcref: ViewContainerRef) {}
}
describe('API', () => {
function embeddedTemplate(rf: RenderFlags, ctx: any) {
if (rf & RenderFlags.Create) {
text(0);
}
if (rf & RenderFlags.Update) {
textBinding(0, bind(ctx.name));
}
}
function createView(s: string, index?: number) {
directiveInstance !.vcref.createEmbeddedView(directiveInstance !.tplRef, {name: s}, index);
}
/**
* <ng-template #foo>
* {{name}}
* </ng-template>
* <p vcref="" [tplRef]="foo">
* </p>
*/
function createTemplate() {
container(0, embeddedTemplate);
elementStart(1, 'p', ['vcref', '']);
elementEnd();
}
function updateTemplate() {
const tplRef = getOrCreateTemplateRef(getOrCreateNodeInjectorForNode(load(0)));
elementProperty(1, 'tplRef', bind(tplRef));
}
describe('createEmbeddedView (incl. insert)', () => {
it('should work on elements', () => {
function createTemplate() {
container(0, embeddedTemplate);
elementStart(1, 'header', ['vcref', '']);
elementEnd();
elementStart(2, 'footer');
elementEnd();
}
const fixture = new TemplateFixture(createTemplate, updateTemplate, [DirectiveWithVCRef]);
expect(fixture.html).toEqual('<header vcref=""></header><footer></footer>');
createView('A');
fixture.update();
expect(fixture.html).toEqual('<header vcref=""></header>A<footer></footer>');
createView('B');
createView('C');
fixture.update();
expect(fixture.html).toEqual('<header vcref=""></header>ABC<footer></footer>');
createView('Y', 0);
fixture.update();
expect(fixture.html).toEqual('<header vcref=""></header>YABC<footer></footer>');
expect(() => { createView('Z', -1); }).toThrow();
expect(() => { createView('Z', 5); }).toThrow();
});
it('should work on components', () => {
class HeaderComponent {
static ngComponentDef = defineComponent({
type: HeaderComponent,
selectors: [['header-cmp']],
factory: () => new HeaderComponent(),
template: (rf: RenderFlags, cmp: HeaderComponent) => {}
});
}
function createTemplate() {
container(0, embeddedTemplate);
elementStart(1, 'header-cmp', ['vcref', '']);
elementEnd();
elementStart(2, 'footer');
elementEnd();
}
const fixture = new TemplateFixture(
createTemplate, updateTemplate, [HeaderComponent, DirectiveWithVCRef]);
expect(fixture.html).toEqual('<header-cmp vcref=""></header-cmp><footer></footer>');
createView('A');
fixture.update();
expect(fixture.html).toEqual('<header-cmp vcref=""></header-cmp>A<footer></footer>');
createView('B');
createView('C');
fixture.update();
expect(fixture.html).toEqual('<header-cmp vcref=""></header-cmp>ABC<footer></footer>');
createView('Y', 0);
fixture.update();
expect(fixture.html).toEqual('<header-cmp vcref=""></header-cmp>YABC<footer></footer>');
expect(() => { createView('Z', -1); }).toThrow();
expect(() => { createView('Z', 5); }).toThrow();
});
it('should work on containers', () => {
function createTemplate() {
container(0, embeddedTemplate, undefined, ['vcref', '']);
elementStart(1, 'footer');
elementEnd();
}
function updateTemplate() {
const tplRef = getOrCreateTemplateRef(getOrCreateNodeInjectorForNode(load(0)));
elementProperty(0, 'tplRef', bind(tplRef));
containerRefreshStart(0);
let rf1 = embeddedViewStart(1);
if (rf1 & RenderFlags.Create) {
elementStart(0, 'header');
elementEnd();
}
embeddedViewEnd();
containerRefreshEnd();
}
const fixture = new TemplateFixture(createTemplate, updateTemplate, [DirectiveWithVCRef]);
expect(fixture.html).toEqual('<header></header><footer></footer>');
createView('A');
fixture.update();
expect(fixture.html).toEqual('<header></header>A<footer></footer>');
createView('B');
createView('C');
fixture.update();
expect(fixture.html).toEqual('<header></header>ABC<footer></footer>');
createView('Y', 0);
fixture.update();
expect(fixture.html).toEqual('<header></header>YABC<footer></footer>');
expect(() => { createView('Z', -1); }).toThrow();
expect(() => { createView('Z', 5); }).toThrow();
});
it('should add embedded views at the right position in the DOM tree (ng-template next to other ng-template)',
() => {
let directiveInstances: TestDirective[] = [];
class TestDirective {
static ngDirectiveDef = defineDirective({
type: TestDirective,
selectors: [['', 'testdir', '']],
factory: () => {
const instance = new TestDirective(injectViewContainerRef(), injectTemplateRef());
directiveInstances.push(instance);
return instance;
}
});
constructor(private _vcRef: ViewContainerRef, private _tplRef: TemplateRef<{}>) {}
insertTpl(ctx: {}) { this._vcRef.createEmbeddedView(this._tplRef, ctx); }
remove(index?: number) { this._vcRef.remove(index); }
}
function EmbeddedTemplateA(rf: RenderFlags, ctx: any) {
if (rf & RenderFlags.Create) {
text(0, 'A');
}
}
function EmbeddedTemplateB(rf: RenderFlags, ctx: any) {
if (rf & RenderFlags.Create) {
text(0, 'B');
}
}
/**
* before|
* <ng-template directive>A<ng-template>
* <ng-template directive>B<ng-template>
* |after
*/
class TestComponent {
testDir: TestDirective;
static ngComponentDef = defineComponent({
type: TestComponent,
selectors: [['test-cmp']],
factory: () => new TestComponent(),
template: (rf: RenderFlags, cmp: TestComponent) => {
if (rf & RenderFlags.Create) {
text(0, 'before|');
container(1, EmbeddedTemplateA, undefined, ['testdir', '']);
container(2, EmbeddedTemplateB, undefined, ['testdir', '']);
text(3, '|after');
}
},
directives: [TestDirective]
});
}
const fixture = new ComponentFixture(TestComponent);
expect(fixture.html).toEqual('before||after');
directiveInstances ![1].insertTpl({});
expect(fixture.html).toEqual('before|B|after');
directiveInstances ![0].insertTpl({});
expect(fixture.html).toEqual('before|AB|after');
});
it('should add embedded views at the right position in the DOM tree (ng-template next to a JS block)',
() => {
let directiveInstance: TestDirective;
class TestDirective {
static ngDirectiveDef = defineDirective({
type: TestDirective,
selectors: [['', 'testdir', '']],
factory: () => directiveInstance =
new TestDirective(injectViewContainerRef(), injectTemplateRef())
});
constructor(private _vcRef: ViewContainerRef, private _tplRef: TemplateRef<{}>) {}
insertTpl(ctx: {}) { this._vcRef.createEmbeddedView(this._tplRef, ctx); }
remove(index?: number) { this._vcRef.remove(index); }
}
function EmbeddedTemplateA(rf: RenderFlags, ctx: any) {
if (rf & RenderFlags.Create) {
text(0, 'A');
}
}
/**
* before|
* <ng-template directive>A<ng-template>
* % if (condition) {
* B
* }
* |after
*/
class TestComponent {
condition = false;
testDir: TestDirective;
static ngComponentDef = defineComponent({
type: TestComponent,
selectors: [['test-cmp']],
factory: () => new TestComponent(),
template: (rf: RenderFlags, cmp: TestComponent) => {
if (rf & RenderFlags.Create) {
text(0, 'before|');
container(1, EmbeddedTemplateA, undefined, ['testdir', '']);
container(2);
text(3, '|after');
}
if (rf & RenderFlags.Update) {
containerRefreshStart(2);
{
if (cmp.condition) {
let rf1 = embeddedViewStart(0);
{
if (rf1 & RenderFlags.Create) {
text(0, 'B');
}
}
embeddedViewEnd();
}
}
containerRefreshEnd();
}
},
directives: [TestDirective]
});
}
const fixture = new ComponentFixture(TestComponent);
expect(fixture.html).toEqual('before||after');
fixture.component.condition = true;
fixture.update();
expect(fixture.html).toEqual('before|B|after');
directiveInstance !.insertTpl({});
expect(fixture.html).toEqual('before|AB|after');
fixture.component.condition = false;
fixture.update();
expect(fixture.html).toEqual('before|A|after');
directiveInstance !.insertTpl({});
expect(fixture.html).toEqual('before|AA|after');
fixture.component.condition = true;
fixture.update();
expect(fixture.html).toEqual('before|AAB|after');
});
});
describe('detach', () => {
it('should detach the right embedded view when an index is specified', () => {
const fixture = new TemplateFixture(createTemplate, updateTemplate, [DirectiveWithVCRef]);
createView('A');
createView('B');
createView('C');
createView('D');
createView('E');
fixture.update();
expect(fixture.html).toEqual('<p vcref=""></p>ABCDE');
directiveInstance !.vcref.detach(3);
fixture.update();
expect(fixture.html).toEqual('<p vcref=""></p>ABCE');
directiveInstance !.vcref.detach(0);
fixture.update();
expect(fixture.html).toEqual('<p vcref=""></p>BCE');
expect(() => { directiveInstance !.vcref.detach(-1); }).toThrow();
expect(() => { directiveInstance !.vcref.detach(42); }).toThrow();
});
it('should detach the last embedded view when no index is specified', () => {
const fixture = new TemplateFixture(createTemplate, updateTemplate, [DirectiveWithVCRef]);
createView('A');
createView('B');
createView('C');
createView('D');
createView('E');
fixture.update();
expect(fixture.html).toEqual('<p vcref=""></p>ABCDE');
directiveInstance !.vcref.detach();
fixture.update();
expect(fixture.html).toEqual('<p vcref=""></p>ABCD');
});
});
describe('length', () => {
it('should return the number of embedded views', () => {
const fixture = new TemplateFixture(createTemplate, updateTemplate, [DirectiveWithVCRef]);
expect(directiveInstance !.vcref.length).toEqual(0);
createView('A');
createView('B');
createView('C');
fixture.update();
expect(directiveInstance !.vcref.length).toEqual(3);
directiveInstance !.vcref.detach(1);
fixture.update();
expect(directiveInstance !.vcref.length).toEqual(2);
directiveInstance !.vcref.clear();
fixture.update();
expect(directiveInstance !.vcref.length).toEqual(0);
});
});
describe('get and indexOf', () => {
it('should retrieve a ViewRef from its index, and vice versa', () => {
const fixture = new TemplateFixture(createTemplate, updateTemplate, [DirectiveWithVCRef]);
createView('A');
createView('B');
createView('C');
fixture.update();
let viewRef = directiveInstance !.vcref.get(0);
expect(directiveInstance !.vcref.indexOf(viewRef !)).toEqual(0);
viewRef = directiveInstance !.vcref.get(1);
expect(directiveInstance !.vcref.indexOf(viewRef !)).toEqual(1);
viewRef = directiveInstance !.vcref.get(2);
expect(directiveInstance !.vcref.indexOf(viewRef !)).toEqual(2);
});
it('should handle out of bounds cases', () => {
const fixture = new TemplateFixture(createTemplate, updateTemplate, [DirectiveWithVCRef]);
createView('A');
fixture.update();
expect(directiveInstance !.vcref.get(-1)).toBeNull();
expect(directiveInstance !.vcref.get(42)).toBeNull();
const viewRef = directiveInstance !.vcref.get(0);
directiveInstance !.vcref.remove(0);
expect(directiveInstance !.vcref.indexOf(viewRef !)).toEqual(-1);
});
});
describe('move', () => {
it('should move embedded views and associated DOM nodes without recreating them', () => {
const fixture = new TemplateFixture(createTemplate, updateTemplate, [DirectiveWithVCRef]);
createView('A');
createView('B');
createView('C');
fixture.update();
expect(fixture.html).toEqual('<p vcref=""></p>ABC');
// The DOM is manually modified here to ensure that the text node is actually moved
fixture.hostElement.childNodes[1].nodeValue = '**A**';
expect(fixture.html).toEqual('<p vcref=""></p>**A**BC');
let viewRef = directiveInstance !.vcref.get(0);
directiveInstance !.vcref.move(viewRef !, 2);
fixture.update();
expect(fixture.html).toEqual('<p vcref=""></p>BC**A**');
directiveInstance !.vcref.move(viewRef !, 0);
fixture.update();
expect(fixture.html).toEqual('<p vcref=""></p>**A**BC');
directiveInstance !.vcref.move(viewRef !, 1);
fixture.update();
expect(fixture.html).toEqual('<p vcref=""></p>B**A**C');
expect(() => { directiveInstance !.vcref.move(viewRef !, -1); }).toThrow();
expect(() => { directiveInstance !.vcref.move(viewRef !, 42); }).toThrow();
});
});
});
describe('projection', () => {
function embeddedTemplate(rf: RenderFlags, ctx: any) {
if (rf & RenderFlags.Create) {
elementStart(0, 'span');
text(1);
elementEnd();
}
textBinding(1, ctx.name);
}
it('should project the ViewContainerRef content along its host, in an element', () => {
@Component({selector: 'child', template: '<div><ng-content></ng-content></div>'})
class Child {
static ngComponentDef = defineComponent({
type: Child,
selectors: [['child']],
factory: () => new Child(),
template: (rf: RenderFlags, cmp: Child) => {
if (rf & RenderFlags.Create) {
projectionDef(0);
elementStart(1, 'div');
{ projection(2, 0); }
elementEnd();
}
}
});
}
@Component({
selector: 'parent',
template: `
<ng-template #foo>
<span>{{name}}</span>
</ng-template>
<child><header vcref [tplRef]="foo" [name]="name">blah</header></child>`
})
class Parent {
name: string = 'bar';
static ngComponentDef = defineComponent({
type: Parent,
selectors: [['parent']],
factory: () => new Parent(),
template: (rf: RenderFlags, cmp: Parent) => {
if (rf & RenderFlags.Create) {
container(0, embeddedTemplate);
elementStart(1, 'child');
elementStart(2, 'header', ['vcref', '']);
text(3, 'blah');
elementEnd();
elementEnd();
}
let tplRef: any;
if (rf & RenderFlags.Update) {
tplRef = getOrCreateTemplateRef(getOrCreateNodeInjectorForNode(load(0)));
elementProperty(2, 'tplRef', bind(tplRef));
elementProperty(2, 'name', bind(cmp.name));
}
},
directives: [Child, DirectiveWithVCRef]
});
}
const fixture = new ComponentFixture(Parent);
expect(fixture.html).toEqual('<child><div><header vcref="">blah</header></div></child>');
directiveInstance !.vcref.createEmbeddedView(directiveInstance !.tplRef, fixture.component);
fixture.update();
expect(fixture.html)
.toEqual('<child><div><header vcref="">blah</header><span>bar</span></div></child>');
});
it('should project the ViewContainerRef content along its host, in a view', () => {
@Component({
selector: 'child-with-view',
template: `
% if (show) {
<ng-content></ng-content>
% }`
})
class ChildWithView {
show: boolean = true;
static ngComponentDef = defineComponent({
type: ChildWithView,
selectors: [['child-with-view']],
factory: () => new ChildWithView(),
template: (rf: RenderFlags, cmp: ChildWithView) => {
if (rf & RenderFlags.Create) {
projectionDef(0);
container(1);
}
if (rf & RenderFlags.Update) {
containerRefreshStart(1);
if (cmp.show) {
let rf0 = embeddedViewStart(0);
if (rf0 & RenderFlags.Create) {
projection(0, 0);
}
embeddedViewEnd();
}
containerRefreshEnd();
}
}
});
}
@Component({
selector: 'parent',
template: `
<ng-template #foo>
<span>{{name}}</span>
</ng-template>
<child-with-view>
<header vcref [tplRef]="foo" [name]="name">blah</header>
</child-with-view>`
})
class Parent {
name: string = 'bar';
static ngComponentDef = defineComponent({
type: Parent,
selectors: [['parent']],
factory: () => new Parent(),
template: (rf: RenderFlags, cmp: Parent) => {
if (rf & RenderFlags.Create) {
container(0, embeddedTemplate);
elementStart(1, 'child-with-view');
elementStart(2, 'header', ['vcref', '']);
text(3, 'blah');
elementEnd();
elementEnd();
}
if (rf & RenderFlags.Update) {
const tplRef = getOrCreateTemplateRef(getOrCreateNodeInjectorForNode(load(0)));
elementProperty(2, 'tplRef', bind(tplRef));
elementProperty(2, 'name', bind(cmp.name));
}
},
directives: [ChildWithView, DirectiveWithVCRef]
});
}
const fixture = new ComponentFixture(Parent);
expect(fixture.html)
.toEqual('<child-with-view><header vcref="">blah</header></child-with-view>');
directiveInstance !.vcref.createEmbeddedView(directiveInstance !.tplRef, fixture.component);
fixture.update();
expect(fixture.html)
.toEqual(
'<child-with-view><header vcref="">blah</header><span>bar</span></child-with-view>');
});
describe('with select', () => {
@Component({
selector: 'child-with-selector',
template: `
<first><ng-content select="header"></ng-content></first>
<second><ng-content></ng-content></second>`
})
class ChildWithSelector {
static ngComponentDef = defineComponent({
type: ChildWithSelector,
selectors: [['child-with-selector']],
factory: () => new ChildWithSelector(),
template: (rf: RenderFlags, cmp: ChildWithSelector) => {
if (rf & RenderFlags.Create) {
projectionDef(0, [[['header']]], ['header']);
elementStart(1, 'first');
{ projection(2, 0, 1); }
elementEnd();
elementStart(3, 'second');
{ projection(4, 0); }
elementEnd();
}
},
directives: [ChildWithSelector, DirectiveWithVCRef]
});
}
it('should project the ViewContainerRef content along its host, when the host matches a selector',
() => {
@Component({
selector: 'parent',
template: `
<ng-template #foo>
<span>{{name}}</span>
</ng-template>
<child-with-selector><header vcref [tplRef]="foo" [name]="name">blah</header></child-with-selector>`
})
class Parent {
name: string = 'bar';
static ngComponentDef = defineComponent({
type: Parent,
selectors: [['parent']],
factory: () => new Parent(),
template: (rf: RenderFlags, cmp: Parent) => {
let tplRef: any;
if (rf & RenderFlags.Create) {
container(0, embeddedTemplate);
elementStart(1, 'child-with-selector');
elementStart(2, 'header', ['vcref', '']);
text(3, 'blah');
elementEnd();
elementEnd();
}
if (rf & RenderFlags.Update) {
tplRef = getOrCreateTemplateRef(getOrCreateNodeInjectorForNode(load(0)));
elementProperty(2, 'tplRef', bind(tplRef));
elementProperty(2, 'name', bind(cmp.name));
}
},
directives: [ChildWithSelector, DirectiveWithVCRef]
});
}
const fixture = new ComponentFixture(Parent);
expect(fixture.html)
.toEqual(
'<child-with-selector><first><header vcref="">blah</header></first><second></second></child-with-selector>');
directiveInstance !.vcref.createEmbeddedView(
directiveInstance !.tplRef, fixture.component);
fixture.update();
expect(fixture.html)
.toEqual(
'<child-with-selector><first><header vcref="">blah</header><span>bar</span></first><second></second></child-with-selector>');
});
it('should not project the ViewContainerRef content, when the host does not match a selector',
() => {
@Component({
selector: 'parent',
template: `
<ng-template #foo>
<span>{{name}}</span>
</ng-template>
<child-with-selector><footer vcref [tplRef]="foo" [name]="name">blah</footer></child-with-selector>`
})
class Parent {
name: string = 'bar';
static ngComponentDef = defineComponent({
type: Parent,
selectors: [['parent']],
factory: () => new Parent(),
template: (rf: RenderFlags, cmp: Parent) => {
let tplRef: any;
if (rf & RenderFlags.Create) {
container(0, embeddedTemplate);
elementStart(1, 'child-with-selector');
elementStart(2, 'footer', ['vcref', '']);
text(3, 'blah');
elementEnd();
elementEnd();
}
if (rf & RenderFlags.Update) {
tplRef = getOrCreateTemplateRef(getOrCreateNodeInjectorForNode(load(0)));
elementProperty(2, 'tplRef', bind(tplRef));
elementProperty(2, 'name', bind(cmp.name));
}
},
directives: [ChildWithSelector, DirectiveWithVCRef]
});
}
const fixture = new ComponentFixture(Parent);
expect(fixture.html)
.toEqual(
'<child-with-selector><first></first><second><footer vcref="">blah</footer></second></child-with-selector>');
directiveInstance !.vcref.createEmbeddedView(
directiveInstance !.tplRef, fixture.component);
fixture.update();
expect(fixture.html)
.toEqual(
'<child-with-selector><first></first><second><footer vcref="">blah</footer><span>bar</span></second></child-with-selector>');
});
});
});
});