@@ -12,6 +12,12 @@ describe('Scope', function() {
12
12
} ) ) ;
13
13
14
14
15
+ it ( 'should expose the constructor' , inject ( function ( $rootScope ) {
16
+ if ( msie ) return ;
17
+ expect ( $rootScope . __proto__ ) . toBe ( $rootScope . constructor . prototype ) ;
18
+ } ) ) ;
19
+
20
+
15
21
it ( 'should not have $root on children, but should inherit' , inject ( function ( $rootScope ) {
16
22
var child = $rootScope . $new ( ) ;
17
23
expect ( child . $root ) . toEqual ( $rootScope ) ;
@@ -672,6 +678,74 @@ describe('Scope', function() {
672
678
expect ( log ) . toEqual ( 'parent.async;child.async;parent.$digest;child.$digest;' ) ;
673
679
} ) ) ;
674
680
681
+ it ( 'should not run another digest for an $$postDigest call' , inject ( function ( $rootScope ) {
682
+ var internalWatchCount = 0 ;
683
+ var externalWatchCount = 0 ;
684
+
685
+ $rootScope . internalCount = 0 ;
686
+ $rootScope . externalCount = 0 ;
687
+
688
+ $rootScope . $evalAsync ( function ( scope ) {
689
+ $rootScope . internalCount ++ ;
690
+ } ) ;
691
+
692
+ $rootScope . $$postDigest ( function ( scope ) {
693
+ $rootScope . externalCount ++ ;
694
+ } ) ;
695
+
696
+ $rootScope . $watch ( 'internalCount' , function ( value ) {
697
+ internalWatchCount = value ;
698
+ } ) ;
699
+ $rootScope . $watch ( 'externalCount' , function ( value ) {
700
+ externalWatchCount = value ;
701
+ } ) ;
702
+
703
+ $rootScope . $digest ( ) ;
704
+
705
+ expect ( internalWatchCount ) . toEqual ( 1 ) ;
706
+ expect ( externalWatchCount ) . toEqual ( 0 ) ;
707
+ } ) ) ;
708
+
709
+ it ( 'should run a $$postDigest call on all child scopes when a parent scope is digested' , inject ( function ( $rootScope ) {
710
+ var parent = $rootScope . $new ( ) ,
711
+ child = parent . $new ( ) ,
712
+ count = 0 ;
713
+
714
+ $rootScope . $$postDigest ( function ( ) {
715
+ count ++ ;
716
+ } ) ;
717
+
718
+ parent . $$postDigest ( function ( ) {
719
+ count ++ ;
720
+ } ) ;
721
+
722
+ child . $$postDigest ( function ( ) {
723
+ count ++ ;
724
+ } ) ;
725
+
726
+ expect ( count ) . toBe ( 0 ) ;
727
+ $rootScope . $digest ( ) ;
728
+ expect ( count ) . toBe ( 3 ) ;
729
+ } ) ) ;
730
+
731
+ it ( 'should run a $$postDigest call even if the child scope is isolated' , inject ( function ( $rootScope ) {
732
+ var parent = $rootScope . $new ( ) ,
733
+ child = parent . $new ( true ) ,
734
+ signature = '' ;
735
+
736
+ parent . $$postDigest ( function ( ) {
737
+ signature += 'A' ;
738
+ } ) ;
739
+
740
+ child . $$postDigest ( function ( ) {
741
+ signature += 'B' ;
742
+ } ) ;
743
+
744
+ expect ( signature ) . toBe ( '' ) ;
745
+ $rootScope . $digest ( ) ;
746
+ expect ( signature ) . toBe ( 'AB' ) ;
747
+ } ) ) ;
748
+
675
749
it ( 'should cause a $digest rerun' , inject ( function ( $rootScope ) {
676
750
$rootScope . log = '' ;
677
751
$rootScope . value = 0 ;
0 commit comments