@@ -7,7 +7,9 @@ import {TranslateModule, TranslateService} from '../src/public_api';
77 selector : 'hmx-app' ,
88 changeDetection : ChangeDetectionStrategy . OnPush ,
99 template : `
10- <div #noKey translate>TEST</div>
10+ <div #noKey translate>
11+ TEST
12+ </div>
1113 <div #withKey [translate]="'TEST'">Some init content</div>
1214 <div #noContent [translate]="'TEST'"></div>
1315 <div #withOtherElements translate>TEST1 <span>Hey</span> TEST2</div>
@@ -53,12 +55,12 @@ describe('TranslateDirective', () => {
5355 } ) ;
5456
5557 it ( 'should translate a string using the container value' , ( ) => {
56- expect ( fixture . componentInstance . noKey . nativeElement . innerHTML ) . toEqual ( 'TEST' ) ;
58+ expect ( fixture . componentInstance . noKey . nativeElement . innerHTML ) . toEqual ( ' TEST ' ) ;
5759
5860 translate . setTranslation ( 'en' , { "TEST" : "This is a test" } ) ;
5961 translate . use ( 'en' ) ;
6062
61- expect ( fixture . componentInstance . noKey . nativeElement . innerHTML ) . toEqual ( 'This is a test' ) ;
63+ expect ( fixture . componentInstance . noKey . nativeElement . innerHTML ) . toEqual ( ' This is a test ' ) ;
6264 } ) ;
6365
6466 it ( 'should translate a string using the key value' , ( ) => {
@@ -81,6 +83,16 @@ describe('TranslateDirective', () => {
8183 expect ( fixture . componentInstance . withOtherElements . nativeElement . innerHTML ) . toEqual ( 'Awesome <span>Hey</span> it works' ) ;
8284 } ) ;
8385
86+ it ( 'should translate first child strings without recursion' , ( ) => {
87+ // replace the content with the key
88+ expect ( fixture . componentInstance . withOtherElements . nativeElement . innerHTML ) . toEqual ( 'TEST1 <span>Hey</span> TEST2' ) ;
89+
90+ translate . setTranslation ( 'en' , { "TEST1" : "TEST2" , "TEST2" : "it works" } ) ;
91+ translate . use ( 'en' ) ;
92+
93+ expect ( fixture . componentInstance . withOtherElements . nativeElement . innerHTML ) . toEqual ( 'TEST2 <span>Hey</span> it works' ) ;
94+ } ) ;
95+
8496 it ( 'should translate a string with params and a key' , ( ) => {
8597 // replace the content with the key
8698 expect ( fixture . componentInstance . withParams . nativeElement . innerHTML ) . toEqual ( 'TEST' ) ;
@@ -119,26 +131,26 @@ describe('TranslateDirective', () => {
119131 } ) ;
120132
121133 it ( 'should update the DOM when the lang changes' , ( ) => {
122- expect ( fixture . componentInstance . noKey . nativeElement . innerHTML ) . toEqual ( 'TEST' ) ;
134+ expect ( fixture . componentInstance . noKey . nativeElement . innerHTML ) . toEqual ( ' TEST ' ) ;
123135 expect ( fixture . componentInstance . withParams . nativeElement . innerHTML ) . toEqual ( 'TEST' ) ;
124136 expect ( fixture . componentInstance . noContent . nativeElement . innerHTML ) . toEqual ( 'TEST' ) ;
125137
126138 translate . setTranslation ( 'en' , { "TEST" : "This is a test" } ) ;
127139 translate . setTranslation ( 'fr' , { "TEST" : "C'est un test" } ) ;
128140
129141 translate . use ( 'en' ) ;
130- expect ( fixture . componentInstance . noKey . nativeElement . innerHTML ) . toEqual ( 'This is a test' ) ;
142+ expect ( fixture . componentInstance . noKey . nativeElement . innerHTML ) . toEqual ( ' This is a test ' ) ;
131143 expect ( fixture . componentInstance . withParams . nativeElement . innerHTML ) . toEqual ( 'This is a test' ) ;
132144 expect ( fixture . componentInstance . noContent . nativeElement . innerHTML ) . toEqual ( 'This is a test' ) ;
133145
134146 translate . use ( 'fr' ) ;
135- expect ( fixture . componentInstance . noKey . nativeElement . innerHTML ) . toEqual ( "C'est un test" ) ;
147+ expect ( fixture . componentInstance . noKey . nativeElement . innerHTML ) . toEqual ( " C'est un test " ) ;
136148 expect ( fixture . componentInstance . withParams . nativeElement . innerHTML ) . toEqual ( "C'est un test" ) ;
137149 expect ( fixture . componentInstance . noContent . nativeElement . innerHTML ) . toEqual ( "C'est un test" ) ;
138150 } ) ;
139151
140152 it ( 'should update the DOM when the lang changes and the translation ends with space' , ( ) => {
141- expect ( fixture . componentInstance . noKey . nativeElement . innerHTML ) . toEqual ( 'TEST' ) ;
153+ expect ( fixture . componentInstance . noKey . nativeElement . innerHTML ) . toEqual ( ' TEST ' ) ;
142154 expect ( fixture . componentInstance . withParams . nativeElement . innerHTML ) . toEqual ( 'TEST' ) ;
143155 expect ( fixture . componentInstance . noContent . nativeElement . innerHTML ) . toEqual ( 'TEST' ) ;
144156
@@ -149,26 +161,26 @@ describe('TranslateDirective', () => {
149161 translate . setTranslation ( 'fr' , { "TEST" : fr } ) ;
150162
151163 translate . use ( 'en' ) ;
152- expect ( fixture . componentInstance . noKey . nativeElement . innerHTML ) . toEqual ( en ) ;
164+ expect ( fixture . componentInstance . noKey . nativeElement . innerHTML ) . toEqual ( ` ${ en } ` ) ;
153165 expect ( fixture . componentInstance . withParams . nativeElement . innerHTML ) . toEqual ( en ) ;
154166 expect ( fixture . componentInstance . noContent . nativeElement . innerHTML ) . toEqual ( en ) ;
155167
156168 translate . use ( 'fr' ) ;
157- expect ( fixture . componentInstance . noKey . nativeElement . innerHTML ) . toEqual ( fr ) ;
169+ expect ( fixture . componentInstance . noKey . nativeElement . innerHTML ) . toEqual ( ` ${ fr } ` ) ;
158170 expect ( fixture . componentInstance . withParams . nativeElement . innerHTML ) . toEqual ( fr ) ;
159171 expect ( fixture . componentInstance . noContent . nativeElement . innerHTML ) . toEqual ( fr ) ;
160172 } ) ;
161173
162174 it ( 'should update the DOM when the default lang changes' , ( ) => {
163- expect ( fixture . componentInstance . noKey . nativeElement . innerHTML ) . toEqual ( 'TEST' ) ;
175+ expect ( fixture . componentInstance . noKey . nativeElement . innerHTML ) . toEqual ( ' TEST ' ) ;
164176
165177 translate . setTranslation ( 'en' , { "TEST" : "This is a test" } ) ;
166178 translate . setTranslation ( 'fr' , { "TEST" : "C'est un test" } ) ;
167179 translate . setDefaultLang ( 'en' ) ;
168- expect ( fixture . componentInstance . noKey . nativeElement . innerHTML ) . toEqual ( 'This is a test' ) ;
180+ expect ( fixture . componentInstance . noKey . nativeElement . innerHTML ) . toEqual ( ' This is a test ' ) ;
169181
170182 translate . setDefaultLang ( 'fr' ) ;
171- expect ( fixture . componentInstance . noKey . nativeElement . innerHTML ) . toEqual ( "C'est un test" ) ;
183+ expect ( fixture . componentInstance . noKey . nativeElement . innerHTML ) . toEqual ( " C'est un test " ) ;
172184 } ) ;
173185
174186 it ( 'should unsubscribe from lang change subscription on destroy' , ( ) => {
0 commit comments