@@ -36,7 +36,7 @@ describe('ngSwitch', function() {
36
36
} ) ) ;
37
37
38
38
39
- it ( 'should show all switch-whens that match the current value' , inject ( function ( $rootScope , $compile ) {
39
+ it ( 'should show all switch-whens that match the current value' , inject ( function ( $rootScope , $compile , $$rAF ) {
40
40
element = $compile (
41
41
'<ul ng-switch="select">' +
42
42
'<li ng-switch-when="1">first:{{name}}</li>' +
@@ -54,14 +54,18 @@ describe('ngSwitch', function() {
54
54
$rootScope . name = 'shyam' ;
55
55
$rootScope . $apply ( ) ;
56
56
expect ( element . text ( ) ) . toEqual ( 'first:shyam, first too:shyam' ) ;
57
+
57
58
$rootScope . select = 2 ;
58
59
$rootScope . $apply ( ) ;
60
+ $$rAF . flush ( ) ;
59
61
expect ( element . text ( ) ) . toEqual ( 'second:shyam' ) ;
60
62
$rootScope . name = 'misko' ;
61
63
$rootScope . $apply ( ) ;
62
64
expect ( element . text ( ) ) . toEqual ( 'second:misko' ) ;
65
+
63
66
$rootScope . select = true ;
64
67
$rootScope . $apply ( ) ;
68
+ $$rAF . flush ( ) ;
65
69
expect ( element . text ( ) ) . toEqual ( 'true:misko' ) ;
66
70
} ) ) ;
67
71
@@ -278,7 +282,7 @@ describe('ngSwitch', function() {
278
282
} ) ) ;
279
283
280
284
281
- it ( 'should properly support case labels with different numbers of transclude fns' , inject ( function ( $rootScope , $compile ) {
285
+ it ( 'should properly support case labels with different numbers of transclude fns' , inject ( function ( $rootScope , $compile , $$rAF ) {
282
286
element = $compile (
283
287
'<div ng-switch="mode">' +
284
288
'<p ng-switch-when="a">Block1</p>' +
@@ -292,16 +296,18 @@ describe('ngSwitch', function() {
292
296
293
297
$rootScope . $apply ( 'mode = "b"' ) ;
294
298
expect ( element . children ( ) . length ) . toBe ( 1 ) ;
299
+ $$rAF . flush ( ) ;
295
300
296
301
$rootScope . $apply ( 'mode = "a"' ) ;
297
302
expect ( element . children ( ) . length ) . toBe ( 2 ) ;
303
+ $$rAF . flush ( ) ;
298
304
299
305
$rootScope . $apply ( 'mode = "b"' ) ;
300
306
expect ( element . children ( ) . length ) . toBe ( 1 ) ;
301
307
} ) ) ;
302
308
303
309
304
- it ( 'should not trigger a digest when an element is removed' , inject ( function ( $$rAF , $compile , $rootScope , $timeout ) {
310
+ it ( 'should not trigger a digest after an element is removed' , inject ( function ( $$rAF , $compile , $rootScope , $timeout ) {
305
311
var spy = spyOn ( $rootScope , '$digest' ) . and . callThrough ( ) ;
306
312
307
313
$rootScope . select = 1 ;
@@ -328,6 +334,12 @@ describe('ngSwitch', function() {
328
334
329
335
330
336
describe ( 'ngSwitchWhen separator' , function ( ) {
337
+ var $$rAF ;
338
+
339
+ beforeEach ( inject ( function ( _$$rAF_ ) {
340
+ $$rAF = _$$rAF_ ;
341
+ } ) ) ;
342
+
331
343
it ( 'should be possible to define a separator' , inject ( function ( $rootScope , $compile ) {
332
344
element = $compile (
333
345
'<div ng-switch="mode">' +
@@ -341,9 +353,13 @@ describe('ngSwitch', function() {
341
353
expect ( element . children ( ) . length ) . toBe ( 2 ) ;
342
354
expect ( element . text ( ) ) . toBe ( 'Block1|Block2|' ) ;
343
355
$rootScope . $apply ( 'mode = "b"' ) ;
356
+ $$rAF . flush ( ) ;
357
+
344
358
expect ( element . children ( ) . length ) . toBe ( 1 ) ;
345
359
expect ( element . text ( ) ) . toBe ( 'Block1|' ) ;
346
360
$rootScope . $apply ( 'mode = "c"' ) ;
361
+ $$rAF . flush ( ) ;
362
+
347
363
expect ( element . children ( ) . length ) . toBe ( 1 ) ;
348
364
expect ( element . text ( ) ) . toBe ( 'Block3|' ) ;
349
365
} ) ) ;
@@ -362,9 +378,13 @@ describe('ngSwitch', function() {
362
378
expect ( element . children ( ) . length ) . toBe ( 2 ) ;
363
379
expect ( element . text ( ) ) . toBe ( 'Block1|Block2|' ) ;
364
380
$rootScope . $apply ( 'mode = ""' ) ;
381
+ $$rAF . flush ( ) ;
382
+
365
383
expect ( element . children ( ) . length ) . toBe ( 1 ) ;
366
384
expect ( element . text ( ) ) . toBe ( 'Block1|' ) ;
367
385
$rootScope . $apply ( 'mode = "c"' ) ;
386
+ $$rAF . flush ( ) ;
387
+
368
388
expect ( element . children ( ) . length ) . toBe ( 1 ) ;
369
389
expect ( element . text ( ) ) . toBe ( 'Block3|' ) ;
370
390
} ) ) ;
@@ -383,9 +403,13 @@ describe('ngSwitch', function() {
383
403
expect ( element . children ( ) . length ) . toBe ( 2 ) ;
384
404
expect ( element . text ( ) ) . toBe ( 'Block1|Block2|' ) ;
385
405
$rootScope . $apply ( 'mode = "b"' ) ;
406
+ $$rAF . flush ( ) ;
407
+
386
408
expect ( element . children ( ) . length ) . toBe ( 1 ) ;
387
409
expect ( element . text ( ) ) . toBe ( 'Block1|' ) ;
388
410
$rootScope . $apply ( 'mode = "c"' ) ;
411
+ $$rAF . flush ( ) ;
412
+
389
413
expect ( element . children ( ) . length ) . toBe ( 1 ) ;
390
414
expect ( element . text ( ) ) . toBe ( 'Block3|' ) ;
391
415
} ) ) ;
@@ -404,9 +428,13 @@ describe('ngSwitch', function() {
404
428
expect ( element . children ( ) . length ) . toBe ( 2 ) ;
405
429
expect ( element . text ( ) ) . toBe ( 'Block1|Block2|' ) ;
406
430
$rootScope . $apply ( 'mode = "b|a"' ) ;
431
+ $$rAF . flush ( ) ;
432
+
407
433
expect ( element . children ( ) . length ) . toBe ( 1 ) ;
408
434
expect ( element . text ( ) ) . toBe ( 'Block1|' ) ;
409
435
$rootScope . $apply ( 'mode = "c"' ) ;
436
+ $$rAF . flush ( ) ;
437
+
410
438
expect ( element . children ( ) . length ) . toBe ( 1 ) ;
411
439
expect ( element . text ( ) ) . toBe ( 'Block3|' ) ;
412
440
} ) ) ;
@@ -425,9 +453,13 @@ describe('ngSwitch', function() {
425
453
expect ( element . children ( ) . length ) . toBe ( 2 ) ;
426
454
expect ( element . text ( ) ) . toBe ( 'Block1|Block2|' ) ;
427
455
$rootScope . $apply ( 'mode = "b"' ) ;
456
+ $$rAF . flush ( ) ;
457
+
428
458
expect ( element . children ( ) . length ) . toBe ( 1 ) ;
429
459
expect ( element . text ( ) ) . toBe ( 'Block1|' ) ;
430
460
$rootScope . $apply ( 'mode = "c"' ) ;
461
+ $$rAF . flush ( ) ;
462
+
431
463
expect ( element . children ( ) . length ) . toBe ( 1 ) ;
432
464
expect ( element . text ( ) ) . toBe ( 'Block3|' ) ;
433
465
} ) ) ;
0 commit comments