|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -import {Component, ComponentFactoryResolver, Directive, EmbeddedViewRef, NgModuleRef, Pipe, PipeTransform, RendererFactory2, TemplateRef, ViewContainerRef, createInjector, defineInjector, ɵAPP_ROOT as APP_ROOT, ɵNgModuleDef as NgModuleDef} from '../../src/core'; |
| 9 | +import {Component, ComponentFactoryResolver, ElementRef, EmbeddedViewRef, NgModuleRef, Pipe, PipeTransform, RendererFactory2, TemplateRef, ViewContainerRef, createInjector, defineInjector, ɵAPP_ROOT as APP_ROOT, ɵNgModuleDef as NgModuleDef} from '../../src/core'; |
10 | 10 | import {getOrCreateNodeInjectorForNode, getOrCreateTemplateRef} from '../../src/render3/di';
|
11 | 11 | import {AttributeMarker, NgOnChangesFeature, defineComponent, defineDirective, definePipe, injectComponentFactoryResolver, injectTemplateRef, injectViewContainerRef} from '../../src/render3/index';
|
12 | 12 | import {bind, container, containerRefreshEnd, containerRefreshStart, element, elementEnd, elementProperty, elementStart, embeddedViewEnd, embeddedViewStart, interpolation1, interpolation3, load, loadDirective, nextContext, projection, projectionDef, reserveSlots, text, textBinding} from '../../src/render3/instructions';
|
@@ -1035,6 +1035,66 @@ describe('ViewContainerRef', () => {
|
1035 | 1035 | '<p vcref=""></p><embedded-cmp-with-ngcontent>12<hr>34</embedded-cmp-with-ngcontent>');
|
1036 | 1036 | });
|
1037 | 1037 | });
|
| 1038 | + |
| 1039 | + describe('getters', () => { |
| 1040 | + it('should work on elements', () => { |
| 1041 | + function createTemplate() { |
| 1042 | + elementStart(0, 'header', ['vcref', '']); |
| 1043 | + elementEnd(); |
| 1044 | + elementStart(1, 'footer'); |
| 1045 | + elementEnd(); |
| 1046 | + } |
| 1047 | + |
| 1048 | + new TemplateFixture(createTemplate, undefined, [DirectiveWithVCRef]); |
| 1049 | + |
| 1050 | + expect(directiveInstance !.vcref.element.nativeElement.tagName.toLowerCase()) |
| 1051 | + .toEqual('header'); |
| 1052 | + expect( |
| 1053 | + directiveInstance !.vcref.injector.get(ElementRef).nativeElement.tagName.toLowerCase()) |
| 1054 | + .toEqual('header'); |
| 1055 | + expect(() => directiveInstance !.vcref.parentInjector.get(ElementRef)).toThrow(); |
| 1056 | + }); |
| 1057 | + |
| 1058 | + it('should work on components', () => { |
| 1059 | + const HeaderComponent = |
| 1060 | + createComponent('header-cmp', function(rf: RenderFlags, ctx: any) {}); |
| 1061 | + |
| 1062 | + function createTemplate() { |
| 1063 | + elementStart(0, 'header-cmp', ['vcref', '']); |
| 1064 | + elementEnd(); |
| 1065 | + elementStart(1, 'footer'); |
| 1066 | + elementEnd(); |
| 1067 | + } |
| 1068 | + |
| 1069 | + new TemplateFixture(createTemplate, undefined, [HeaderComponent, DirectiveWithVCRef]); |
| 1070 | + |
| 1071 | + expect(directiveInstance !.vcref.element.nativeElement.tagName.toLowerCase()) |
| 1072 | + .toEqual('header-cmp'); |
| 1073 | + expect( |
| 1074 | + directiveInstance !.vcref.injector.get(ElementRef).nativeElement.tagName.toLowerCase()) |
| 1075 | + .toEqual('header-cmp'); |
| 1076 | + expect(() => directiveInstance !.vcref.parentInjector.get(ElementRef)).toThrow(); |
| 1077 | + }); |
| 1078 | + |
| 1079 | + it('should work on containers', () => { |
| 1080 | + function createTemplate() { |
| 1081 | + container(0, embeddedTemplate, undefined, ['vcref', '']); |
| 1082 | + elementStart(1, 'footer'); |
| 1083 | + elementEnd(); |
| 1084 | + } |
| 1085 | + |
| 1086 | + function updateTemplate() { |
| 1087 | + containerRefreshStart(0); |
| 1088 | + containerRefreshEnd(); |
| 1089 | + } |
| 1090 | + |
| 1091 | + new TemplateFixture(createTemplate, updateTemplate, [DirectiveWithVCRef]); |
| 1092 | + expect(directiveInstance !.vcref.element.nativeElement.textContent).toEqual('container'); |
| 1093 | + expect(directiveInstance !.vcref.injector.get(ElementRef).nativeElement.textContent) |
| 1094 | + .toEqual('container'); |
| 1095 | + expect(() => directiveInstance !.vcref.parentInjector.get(ElementRef)).toThrow(); |
| 1096 | + }); |
| 1097 | + }); |
1038 | 1098 | });
|
1039 | 1099 |
|
1040 | 1100 | describe('projection', () => {
|
|
0 commit comments