@@ -16,6 +16,7 @@ import { View, fontInternalProperty, backgroundInternalProperty } from "tns-core
1616import { nsTestBedAfterEach , nsTestBedBeforeEach , nsTestBedRender } from "nativescript-angular/testing" ;
1717import { ComponentFixture , TestBed , async } from "@angular/core/testing" ;
1818import { Observable , ReplaySubject } from "rxjs" ;
19+ import { Label } from "tns-core-modules/ui/label/label" ;
1920
2021@Component ( {
2122 template : `<StackLayout><Label text="Layout"></Label></StackLayout>`
@@ -97,6 +98,37 @@ export class StyledLabelCmp2 {
9798 }
9899}
99100
101+ @Component ( {
102+ selector : "host-styled" ,
103+ styles : [ `
104+ Label {
105+ color: blue;
106+ }
107+
108+ :host Label {
109+ color: red;
110+ }
111+ `
112+ ] ,
113+ template : `<Label text="Styled!"></Label>`
114+ } )
115+ export class HostStyledCmp {
116+ constructor ( public elementRef : ElementRef < ProxyViewContainer > ) {
117+ }
118+ }
119+
120+ @Component ( {
121+ selector : "host-styled-parent" ,
122+ template : `
123+ <host-styled></host-styled>
124+ <host-styled></host-styled>
125+ `
126+ } )
127+ export class HostStyledParentCmp {
128+ constructor ( public elementRef : ElementRef < ProxyViewContainer > ) {
129+ }
130+ }
131+
100132@Component ( {
101133 selector : "ng-if-label" ,
102134 template : `<Label *ngIf="show" text="iffed"></Label>`
@@ -251,6 +283,7 @@ describe("Renderer E2E", () => {
251283 LayoutWithLabel , LabelCmp , LabelContainer ,
252284 ProjectableCmp , ProjectionContainer ,
253285 StyledLabelCmp , StyledLabelCmp2 ,
286+ HostStyledCmp , HostStyledParentCmp ,
254287 NgIfLabel , NgIfThenElseComponent , NgIfMultiple ,
255288 NgIfTwoElements , NgIfMultiple ,
256289 NgIfElseComponent , NgIfThenElseComponent ,
@@ -293,6 +326,18 @@ describe("Renderer E2E", () => {
293326 } ) ;
294327 } ) ;
295328
329+ it ( "applies component :host styles" , ( ) => {
330+ return nsTestBedRender ( HostStyledParentCmp ) . then ( ( fixture ) => {
331+ const proxyView = fixture . componentRef . instance . elementRef . nativeElement ;
332+
333+ for ( let i = 0 ; i < 2 ; i += 1 ) {
334+ const child = proxyView . getChildAt ( i ) as ProxyViewContainer ;
335+ const label = child . getChildAt ( 0 ) as Label ;
336+ assert . equal ( Red , label . style . color . hex ) ;
337+ }
338+ } ) ;
339+ } ) ;
340+
296341 it ( "applies component styles from multiple sources" , ( ) => {
297342 return nsTestBedRender ( StyledLabelCmp2 ) . then ( ( fixture ) => {
298343 const componentRef : ComponentRef < StyledLabelCmp2 > = fixture . componentRef ;
0 commit comments