@@ -233,7 +233,7 @@ describe('<md-tabs>', function () {
233
233
} ) ;
234
234
235
235
it ( 'updates pagination and ink styles when string labels change' , function ( done ) {
236
- inject ( function ( $rootScope ) {
236
+ inject ( function ( $rootScope , $timeout ) {
237
237
// Setup our initial label
238
238
$rootScope . $apply ( 'label = "Some Label"' ) ;
239
239
@@ -242,21 +242,72 @@ describe('<md-tabs>', function () {
242
242
var tabs = setup ( template ) ;
243
243
var ctrl = tabs . controller ( 'mdTabs' ) ;
244
244
245
- // Setup spies
246
- spyOn ( ctrl , 'updatePagination' ) ;
247
- spyOn ( ctrl , 'updateInkBarStyles' ) ;
248
-
249
- // Change the label
250
- $rootScope . $apply ( 'label="Another Label"' ) ;
245
+ // Flush the tabs controller timeout for initialization.
246
+ $timeout . flush ( ) ;
251
247
252
- // Use window.setTimeout to add our expectations to the end of the call stack, after the
248
+ // After the first timeout the mutation observer should have been fired once, because
249
+ // the initialization of the dummy tabs, already causes some mutations.
250
+ // Use setTimeout to add our expectations to the end of the call stack, after the
253
251
// MutationObservers have already fired
254
- window . setTimeout ( function ( ) {
255
- // Fire expectations
256
- expect ( ctrl . updatePagination . calls . count ( ) ) . toBe ( 1 ) ;
257
- expect ( ctrl . updateInkBarStyles . calls . count ( ) ) . toBe ( 1 ) ;
252
+ setTimeout ( function ( ) {
253
+ // Setup spies
254
+ spyOn ( ctrl , 'updatePagination' ) ;
255
+ spyOn ( ctrl , 'updateInkBarStyles' ) ;
256
+
257
+ // Update the label to trigger a new update of the pagination and InkBar styles.
258
+ $rootScope . $apply ( 'label = "Another Label"' ) ;
259
+
260
+ // Use setTimeout to add our expectations to the end of the call stack, after the
261
+ // MutationObservers have already fired
262
+ setTimeout ( function ( ) {
263
+ expect ( ctrl . updatePagination ) . toHaveBeenCalledTimes ( 1 ) ;
264
+ expect ( ctrl . updateInkBarStyles ) . toHaveBeenCalledTimes ( 1 ) ;
265
+
266
+ done ( ) ;
267
+ } ) ;
268
+ } ) ;
269
+ } )
270
+ } ) ;
258
271
259
- done ( ) ;
272
+ it ( 'updates pagination and ink styles when content label changes' , function ( done ) {
273
+ inject ( function ( $rootScope , $timeout ) {
274
+ // Setup our initial label
275
+ $rootScope . $apply ( 'label = "Default Label"' ) ;
276
+
277
+ // Init our variables
278
+ var template = '' +
279
+ '<md-tabs>' +
280
+ '<md-tab>' +
281
+ '<md-tab-label>{{ label }}</md-tab-label>' +
282
+ '</md-tab>' +
283
+ '</md-tabs>' ;
284
+
285
+ var tabs = setup ( template ) ;
286
+ var ctrl = tabs . controller ( 'mdTabs' ) ;
287
+
288
+ // Flush the tabs controller timeout for initialization.
289
+ $timeout . flush ( ) ;
290
+
291
+ // After the first timeout the mutation observer should have been fired once, because
292
+ // the initialization of the dummy tabs, already causes some mutations.
293
+ // Use setTimeout to add our expectations to the end of the call stack, after the
294
+ // MutationObservers have already fired
295
+ setTimeout ( function ( ) {
296
+ // Setup spies
297
+ spyOn ( ctrl , 'updatePagination' ) ;
298
+ spyOn ( ctrl , 'updateInkBarStyles' ) ;
299
+
300
+ // Update the label to trigger a new update of the pagination and InkBar styles.
301
+ $rootScope . $apply ( 'label = "New Label"' ) ;
302
+
303
+ // Use setTimeout to add our expectations to the end of the call stack, after the
304
+ // MutationObservers have already fired
305
+ setTimeout ( function ( ) {
306
+ expect ( ctrl . updatePagination ) . toHaveBeenCalledTimes ( 1 ) ;
307
+ expect ( ctrl . updateInkBarStyles ) . toHaveBeenCalledTimes ( 1 ) ;
308
+
309
+ done ( ) ;
310
+ } ) ;
260
311
} ) ;
261
312
} )
262
313
} ) ;
0 commit comments