@@ -16,6 +16,7 @@ import { View, fontInternalProperty, backgroundInternalProperty } from "tns-core
16
16
import { nsTestBedAfterEach , nsTestBedBeforeEach , nsTestBedRender } from "nativescript-angular/testing" ;
17
17
import { ComponentFixture , TestBed , async } from "@angular/core/testing" ;
18
18
import { Observable , ReplaySubject } from "rxjs" ;
19
+ import { Label } from "tns-core-modules/ui/label/label" ;
19
20
20
21
@Component ( {
21
22
template : `<StackLayout><Label text="Layout"></Label></StackLayout>`
@@ -97,6 +98,37 @@ export class StyledLabelCmp2 {
97
98
}
98
99
}
99
100
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
+
100
132
@Component ( {
101
133
selector : "ng-if-label" ,
102
134
template : `<Label *ngIf="show" text="iffed"></Label>`
@@ -251,6 +283,7 @@ describe("Renderer E2E", () => {
251
283
LayoutWithLabel , LabelCmp , LabelContainer ,
252
284
ProjectableCmp , ProjectionContainer ,
253
285
StyledLabelCmp , StyledLabelCmp2 ,
286
+ HostStyledCmp , HostStyledParentCmp ,
254
287
NgIfLabel , NgIfThenElseComponent , NgIfMultiple ,
255
288
NgIfTwoElements , NgIfMultiple ,
256
289
NgIfElseComponent , NgIfThenElseComponent ,
@@ -293,6 +326,18 @@ describe("Renderer E2E", () => {
293
326
} ) ;
294
327
} ) ;
295
328
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
+
296
341
it ( "applies component styles from multiple sources" , ( ) => {
297
342
return nsTestBedRender ( StyledLabelCmp2 ) . then ( ( fixture ) => {
298
343
const componentRef : ComponentRef < StyledLabelCmp2 > = fixture . componentRef ;
0 commit comments