@@ -18,6 +18,11 @@ import {Component, View, NgFor, bind} from 'angular2/angular2';
1818import { NgClass } from 'angular2/src/directives/ng_class' ;
1919import { APP_VIEW_POOL_CAPACITY } from 'angular2/src/core/compiler/view_pool' ;
2020
21+ function detectChangesAndCheck ( rootTC , classes : string , elIndex : number = 0 ) {
22+ rootTC . detectChanges ( ) ;
23+ expect ( rootTC . componentViewChildren [ elIndex ] . nativeElement . className ) . toEqual ( classes ) ;
24+ }
25+
2126export function main ( ) {
2227 describe ( 'binding to CSS class list' , ( ) => {
2328
@@ -33,9 +38,8 @@ export function main() {
3338 rootTC . componentInstance . items = [ [ '0' ] ] ;
3439 rootTC . detectChanges ( ) ;
3540 rootTC . componentInstance . items = [ [ '1' ] ] ;
36- rootTC . detectChanges ( ) ;
37- expect ( rootTC . componentViewChildren [ 1 ] . nativeElement . className )
38- . toEqual ( 'ng-binding 1' ) ;
41+
42+ detectChangesAndCheck ( rootTC , 'ng-binding 1' , 1 ) ;
3943
4044 async . done ( ) ;
4145 } ) ;
@@ -52,10 +56,7 @@ export function main() {
5256 tcb . overrideTemplate ( TestComponent , template )
5357 . createAsync ( TestComponent )
5458 . then ( ( rootTC ) => {
55- rootTC . detectChanges ( ) ;
56- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
57- . toEqual ( 'ng-binding foo' ) ;
58-
59+ detectChangesAndCheck ( rootTC , 'ng-binding foo' ) ;
5960 async . done ( ) ;
6061 } ) ;
6162 } ) ) ;
@@ -68,10 +69,7 @@ export function main() {
6869 tcb . overrideTemplate ( TestComponent , template )
6970 . createAsync ( TestComponent )
7071 . then ( ( rootTC ) => {
71- rootTC . detectChanges ( ) ;
72- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
73- . toEqual ( 'ng-binding foo-bar fooBar' ) ;
74-
72+ detectChangesAndCheck ( rootTC , 'ng-binding foo-bar fooBar' ) ;
7573 async . done ( ) ;
7674 } ) ;
7775 } ) ) ;
@@ -83,14 +81,10 @@ export function main() {
8381 tcb . overrideTemplate ( TestComponent , template )
8482 . createAsync ( TestComponent )
8583 . then ( ( rootTC ) => {
86- rootTC . detectChanges ( ) ;
87- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
88- . toEqual ( 'ng-binding foo' ) ;
84+ detectChangesAndCheck ( rootTC , 'ng-binding foo' ) ;
8985
9086 rootTC . componentInstance . condition = false ;
91- rootTC . detectChanges ( ) ;
92- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
93- . toEqual ( 'ng-binding bar' ) ;
87+ detectChangesAndCheck ( rootTC , 'ng-binding bar' ) ;
9488
9589 async . done ( ) ;
9690 } ) ;
@@ -103,24 +97,16 @@ export function main() {
10397 tcb . overrideTemplate ( TestComponent , template )
10498 . createAsync ( TestComponent )
10599 . then ( ( rootTC ) => {
106- rootTC . detectChanges ( ) ;
107- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
108- . toEqual ( 'ng-binding foo' ) ;
100+ detectChangesAndCheck ( rootTC , 'ng-binding foo' ) ;
109101
110102 StringMapWrapper . set ( rootTC . componentInstance . objExpr , 'bar' , true ) ;
111- rootTC . detectChanges ( ) ;
112- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
113- . toEqual ( 'ng-binding foo bar' ) ;
103+ detectChangesAndCheck ( rootTC , 'ng-binding foo bar' ) ;
114104
115105 StringMapWrapper . set ( rootTC . componentInstance . objExpr , 'baz' , true ) ;
116- rootTC . detectChanges ( ) ;
117- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
118- . toEqual ( 'ng-binding foo bar baz' ) ;
106+ detectChangesAndCheck ( rootTC , 'ng-binding foo bar baz' ) ;
119107
120108 StringMapWrapper . delete ( rootTC . componentInstance . objExpr , 'bar' ) ;
121- rootTC . detectChanges ( ) ;
122- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
123- . toEqual ( 'ng-binding foo baz' ) ;
109+ detectChangesAndCheck ( rootTC , 'ng-binding foo baz' ) ;
124110
125111 async . done ( ) ;
126112 } ) ;
@@ -133,19 +119,13 @@ export function main() {
133119 tcb . overrideTemplate ( TestComponent , template )
134120 . createAsync ( TestComponent )
135121 . then ( ( rootTC ) => {
136- rootTC . detectChanges ( ) ;
137- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
138- . toEqual ( 'ng-binding foo' ) ;
122+ detectChangesAndCheck ( rootTC , 'ng-binding foo' ) ;
139123
140124 rootTC . componentInstance . objExpr = { foo : true , bar : true } ;
141- rootTC . detectChanges ( ) ;
142- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
143- . toEqual ( 'ng-binding foo bar' ) ;
125+ detectChangesAndCheck ( rootTC , 'ng-binding foo bar' ) ;
144126
145127 rootTC . componentInstance . objExpr = { baz : true } ;
146- rootTC . detectChanges ( ) ;
147- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
148- . toEqual ( 'ng-binding baz' ) ;
128+ detectChangesAndCheck ( rootTC , 'ng-binding baz' ) ;
149129
150130 async . done ( ) ;
151131 } ) ;
@@ -161,10 +141,7 @@ export function main() {
161141 tcb . overrideTemplate ( TestComponent , template )
162142 . createAsync ( TestComponent )
163143 . then ( ( rootTC ) => {
164- rootTC . detectChanges ( ) ;
165- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
166- . toEqual ( 'ng-binding foo bar foo-bar fooBar' ) ;
167-
144+ detectChangesAndCheck ( rootTC , 'ng-binding foo bar foo-bar fooBar' ) ;
168145 async . done ( ) ;
169146 } ) ;
170147 } ) ) ;
@@ -176,27 +153,17 @@ export function main() {
176153 tcb . overrideTemplate ( TestComponent , template )
177154 . createAsync ( TestComponent )
178155 . then ( ( rootTC ) => {
179-
180156 var arrExpr : List < string > = rootTC . componentInstance . arrExpr ;
181-
182- rootTC . detectChanges ( ) ;
183- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
184- . toEqual ( 'ng-binding foo' ) ;
157+ detectChangesAndCheck ( rootTC , 'ng-binding foo' ) ;
185158
186159 arrExpr . push ( 'bar' ) ;
187- rootTC . detectChanges ( ) ;
188- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
189- . toEqual ( 'ng-binding foo bar' ) ;
160+ detectChangesAndCheck ( rootTC , 'ng-binding foo bar' ) ;
190161
191162 arrExpr [ 1 ] = 'baz' ;
192- rootTC . detectChanges ( ) ;
193- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
194- . toEqual ( 'ng-binding foo baz' ) ;
163+ detectChangesAndCheck ( rootTC , 'ng-binding foo baz' ) ;
195164
196165 ListWrapper . remove ( rootTC . componentInstance . arrExpr , 'baz' ) ;
197- rootTC . detectChanges ( ) ;
198- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
199- . toEqual ( 'ng-binding foo' ) ;
166+ detectChangesAndCheck ( rootTC , 'ng-binding foo' ) ;
200167
201168 async . done ( ) ;
202169 } ) ;
@@ -209,14 +176,10 @@ export function main() {
209176 tcb . overrideTemplate ( TestComponent , template )
210177 . createAsync ( TestComponent )
211178 . then ( ( rootTC ) => {
212- rootTC . detectChanges ( ) ;
213- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
214- . toEqual ( 'ng-binding foo' ) ;
179+ detectChangesAndCheck ( rootTC , 'ng-binding foo' ) ;
215180
216181 rootTC . componentInstance . arrExpr = [ 'bar' ] ;
217- rootTC . detectChanges ( ) ;
218- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
219- . toEqual ( 'ng-binding bar' ) ;
182+ detectChangesAndCheck ( rootTC , 'ng-binding bar' ) ;
220183
221184 async . done ( ) ;
222185 } ) ;
@@ -232,10 +195,7 @@ export function main() {
232195 tcb . overrideTemplate ( TestComponent , template )
233196 . createAsync ( TestComponent )
234197 . then ( ( rootTC ) => {
235- rootTC . detectChanges ( ) ;
236- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
237- . toEqual ( 'ng-binding foo bar foo-bar fooBar' ) ;
238-
198+ detectChangesAndCheck ( rootTC , 'ng-binding foo bar foo-bar fooBar' ) ;
239199 async . done ( ) ;
240200 } ) ;
241201 } ) ) ;
@@ -247,19 +207,14 @@ export function main() {
247207 tcb . overrideTemplate ( TestComponent , template )
248208 . createAsync ( TestComponent )
249209 . then ( ( rootTC ) => {
250- rootTC . detectChanges ( ) ;
251- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
252- . toEqual ( 'ng-binding foo' ) ;
210+ detectChangesAndCheck ( rootTC , 'ng-binding foo' ) ;
253211
254212 rootTC . componentInstance . strExpr = 'foo bar' ;
255- rootTC . detectChanges ( ) ;
256- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
257- . toEqual ( 'ng-binding foo bar' ) ;
213+ detectChangesAndCheck ( rootTC , 'ng-binding foo bar' ) ;
214+
258215
259216 rootTC . componentInstance . strExpr = 'baz' ;
260- rootTC . detectChanges ( ) ;
261- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
262- . toEqual ( 'ng-binding baz' ) ;
217+ detectChangesAndCheck ( rootTC , 'ng-binding baz' ) ;
263218
264219 async . done ( ) ;
265220 } ) ;
@@ -273,14 +228,10 @@ export function main() {
273228 tcb . overrideTemplate ( TestComponent , template )
274229 . createAsync ( TestComponent )
275230 . then ( ( rootTC ) => {
276- rootTC . detectChanges ( ) ;
277- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
278- . toEqual ( 'ng-binding foo' ) ;
231+ detectChangesAndCheck ( rootTC , 'ng-binding foo' ) ;
279232
280233 rootTC . componentInstance . strExpr = null ;
281- rootTC . detectChanges ( ) ;
282- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
283- . toEqual ( 'ng-binding' ) ;
234+ detectChangesAndCheck ( rootTC , 'ng-binding' ) ;
284235
285236 async . done ( ) ;
286237 } ) ;
@@ -294,19 +245,13 @@ export function main() {
294245 tcb . overrideTemplate ( TestComponent , template )
295246 . createAsync ( TestComponent )
296247 . then ( ( rootTC ) => {
297- rootTC . detectChanges ( ) ;
298- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
299- . toEqual ( 'ng-binding foo' ) ;
248+ detectChangesAndCheck ( rootTC , 'ng-binding foo' ) ;
300249
301250 rootTC . componentInstance . objExpr = null ;
302- rootTC . detectChanges ( ) ;
303- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
304- . toEqual ( 'ng-binding' ) ;
251+ detectChangesAndCheck ( rootTC , 'ng-binding' ) ;
305252
306253 rootTC . componentInstance . objExpr = { 'foo' : false , 'bar' : true } ;
307- rootTC . detectChanges ( ) ;
308- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
309- . toEqual ( 'ng-binding bar' ) ;
254+ detectChangesAndCheck ( rootTC , 'ng-binding bar' ) ;
310255
311256 async . done ( ) ;
312257 } ) ;
@@ -320,14 +265,10 @@ export function main() {
320265 . createAsync ( TestComponent )
321266 . then ( ( rootTC ) => {
322267 StringMapWrapper . set ( rootTC . componentInstance . objExpr , 'bar' , true ) ;
323- rootTC . detectChanges ( ) ;
324- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
325- . toEqual ( 'init foo ng-binding bar' ) ;
268+ detectChangesAndCheck ( rootTC , 'init foo ng-binding bar' ) ;
326269
327270 StringMapWrapper . set ( rootTC . componentInstance . objExpr , 'foo' , false ) ;
328- rootTC . detectChanges ( ) ;
329- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
330- . toEqual ( 'init ng-binding bar' ) ;
271+ detectChangesAndCheck ( rootTC , 'init ng-binding bar' ) ;
331272
332273 async . done ( ) ;
333274 } ) ;
@@ -340,24 +281,16 @@ export function main() {
340281 tcb . overrideTemplate ( TestComponent , template )
341282 . createAsync ( TestComponent )
342283 . then ( ( rootTC ) => {
343- rootTC . detectChanges ( ) ;
344- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
345- . toEqual ( 'init foo ng-binding baz' ) ;
284+ detectChangesAndCheck ( rootTC , 'init foo ng-binding baz' ) ;
346285
347286 StringMapWrapper . set ( rootTC . componentInstance . objExpr , 'bar' , true ) ;
348- rootTC . detectChanges ( ) ;
349- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
350- . toEqual ( 'init foo ng-binding baz bar' ) ;
287+ detectChangesAndCheck ( rootTC , 'init foo ng-binding baz bar' ) ;
351288
352289 StringMapWrapper . set ( rootTC . componentInstance . objExpr , 'foo' , false ) ;
353- rootTC . detectChanges ( ) ;
354- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
355- . toEqual ( 'init ng-binding baz bar' ) ;
290+ detectChangesAndCheck ( rootTC , 'init ng-binding baz bar' ) ;
356291
357292 rootTC . componentInstance . condition = false ;
358- rootTC . detectChanges ( ) ;
359- expect ( rootTC . componentViewChildren [ 0 ] . nativeElement . className )
360- . toEqual ( 'init ng-binding bar' ) ;
293+ detectChangesAndCheck ( rootTC , 'init ng-binding bar' ) ;
361294
362295 async . done ( ) ;
363296 } ) ;
0 commit comments