2
2
3
3
describe ( 'Scope' , function ( ) {
4
4
5
- beforeEach ( inject ( function ( $exceptionHandlerProvider ) {
6
- $exceptionHandlerProvider . mode ( 'log' ) ;
7
- } ) ) ;
8
-
9
-
10
5
describe ( '$root' , function ( ) {
11
6
it ( 'should point to itself' , inject ( function ( $rootScope ) {
12
7
expect ( $rootScope . $root ) . toEqual ( $rootScope ) ;
@@ -122,7 +117,9 @@ describe('Scope', function() {
122
117
} ) ) ;
123
118
124
119
125
- it ( 'should delegate exceptions' , inject ( function ( $rootScope , $exceptionHandler , $log ) {
120
+ it ( 'should delegate exceptions' , inject ( function ( $exceptionHandlerProvider ) {
121
+ $exceptionHandlerProvider . mode ( 'log' ) ;
122
+ } , function ( $rootScope , $exceptionHandler , $log ) {
126
123
$rootScope . $watch ( 'a' , function ( ) { throw new Error ( 'abc' ) ; } ) ;
127
124
$rootScope . a = 1 ;
128
125
$rootScope . $digest ( ) ;
@@ -227,7 +224,7 @@ describe('Scope', function() {
227
224
} ) ) ;
228
225
229
226
230
- it ( 'should prevent infinite recurcion and print print watcher function name or body' ,
227
+ it ( 'should prevent infinite recursion and print print watcher function name or body' ,
231
228
inject ( function ( $rootScope ) {
232
229
$rootScope . $watch ( function watcherA ( ) { return $rootScope . a ; } , function ( self ) { self . b ++ ; } ) ;
233
230
$rootScope . $watch ( function ( ) { return $rootScope . b ; } , function ( self ) { self . a ++ ; } ) ;
@@ -277,7 +274,7 @@ describe('Scope', function() {
277
274
} ) ) ;
278
275
279
276
280
- it ( 'should prevent recursion' , inject ( function ( $rootScope ) {
277
+ it ( 'should prevent $digest recursion' , inject ( function ( $rootScope ) {
281
278
var callCount = 0 ;
282
279
$rootScope . $watch ( 'name' , function ( ) {
283
280
expect ( function ( ) {
@@ -462,7 +459,9 @@ describe('Scope', function() {
462
459
} ) ) ;
463
460
464
461
465
- it ( 'should catch exceptions' , inject ( function ( $rootScope , $exceptionHandler , $log ) {
462
+ it ( 'should catch exceptions' , inject ( function ( $exceptionHandlerProvider ) {
463
+ $exceptionHandlerProvider . mode ( 'log' ) ;
464
+ } , function ( $rootScope , $exceptionHandler , $log ) {
466
465
var log = '' ;
467
466
var child = $rootScope . $new ( ) ;
468
467
$rootScope . $watch ( 'a' , function ( scope , a ) { log += '1' ; } ) ;
@@ -476,7 +475,9 @@ describe('Scope', function() {
476
475
477
476
describe ( 'exceptions' , function ( ) {
478
477
var log ;
479
- beforeEach ( inject ( function ( $rootScope ) {
478
+ beforeEach ( inject ( function ( $exceptionHandlerProvider ) {
479
+ $exceptionHandlerProvider . mode ( 'log' ) ;
480
+ } , function ( $rootScope ) {
480
481
log = '' ;
481
482
$rootScope . $watch ( function ( ) { log += '$digest;' ; } ) ;
482
483
$rootScope . $digest ( ) ;
@@ -502,6 +503,57 @@ describe('Scope', function() {
502
503
expect ( $exceptionHandler . errors ) . toEqual ( [ error ] ) ;
503
504
} ) ) ;
504
505
} ) ;
506
+
507
+
508
+ describe ( 'recursive $apply protection' , function ( ) {
509
+ it ( 'should throw an exception if $apply is called while an $apply is in progress' , inject (
510
+ function ( $rootScope ) {
511
+ expect ( function ( ) {
512
+ $rootScope . $apply ( function ( ) {
513
+ $rootScope . $apply ( ) ;
514
+ } ) ;
515
+ } ) . toThrow ( '$apply already in progress' ) ;
516
+ } ) ) ;
517
+
518
+
519
+ it ( 'should throw an exception if $apply is called while flushing evalAsync queue' , inject (
520
+ function ( $rootScope ) {
521
+ expect ( function ( ) {
522
+ $rootScope . $apply ( function ( ) {
523
+ $rootScope . $evalAsync ( function ( ) {
524
+ $rootScope . $apply ( ) ;
525
+ } ) ;
526
+ } ) ;
527
+ } ) . toThrow ( '$digest already in progress' ) ;
528
+ } ) ) ;
529
+
530
+
531
+ it ( 'should throw an exception if $apply is called while a watch is being initialized' , inject (
532
+ function ( $rootScope ) {
533
+ var childScope1 = $rootScope . $new ( ) ;
534
+ childScope1 . $watch ( 'x' , function ( ) {
535
+ childScope1 . $apply ( ) ;
536
+ } ) ;
537
+ expect ( function ( ) { childScope1 . $apply ( ) ; } ) . toThrow ( '$digest already in progress' ) ;
538
+ } ) ) ;
539
+
540
+
541
+ it ( 'should thrown an exception if $apply in called from a watch fn (after init)' , inject (
542
+ function ( $rootScope ) {
543
+ var childScope2 = $rootScope . $new ( ) ;
544
+ childScope2 . $apply ( function ( ) {
545
+ childScope2 . $watch ( 'x' , function ( scope , newVal , oldVal ) {
546
+ if ( newVal !== oldVal ) {
547
+ childScope2 . $apply ( ) ;
548
+ }
549
+ } ) ;
550
+ } ) ;
551
+
552
+ expect ( function ( ) { childScope2 . $apply ( function ( ) {
553
+ childScope2 . x = 'something' ;
554
+ } ) ; } ) . toThrow ( '$digest already in progress' ) ;
555
+ } ) ) ;
556
+ } ) ;
505
557
} ) ;
506
558
507
559
@@ -561,7 +613,10 @@ describe('Scope', function() {
561
613
log += event . currentScope . id + '>' ;
562
614
}
563
615
564
- beforeEach ( inject ( function ( $rootScope ) {
616
+ beforeEach ( inject (
617
+ function ( $exceptionHandlerProvider ) {
618
+ $exceptionHandlerProvider . mode ( 'log' ) ;
619
+ } , function ( $rootScope ) {
565
620
log = '' ;
566
621
child = $rootScope . $new ( ) ;
567
622
grandChild = child . $new ( ) ;
0 commit comments