@@ -730,6 +730,26 @@ describe('Scope', function() {
730
730
first . $apply ( ) ;
731
731
expect ( log ) . toBe ( '1232323' ) ;
732
732
} ) ) ;
733
+
734
+ it ( 'should decrement anscestor $$listenerCount entries' , inject ( function ( $rootScope ) {
735
+ var EVENT = 'fooEvent' ,
736
+ spy = jasmine . createSpy ( 'listener' ) ,
737
+ firstSecond = first . $new ( ) ;
738
+
739
+ firstSecond . $on ( EVENT , spy ) ;
740
+ middle . $on ( EVENT , spy ) ;
741
+
742
+ expect ( $rootScope . $$listenerCount [ EVENT ] ) . toBe ( 2 ) ;
743
+ expect ( first . $$listenerCount [ EVENT ] ) . toBe ( 1 ) ;
744
+
745
+ firstSecond . $destroy ( ) ;
746
+
747
+ expect ( $rootScope . $$listenerCount [ EVENT ] ) . toBe ( 1 ) ;
748
+ expect ( first . $$listenerCount [ EVENT ] ) . toBeUndefined ( ) ;
749
+
750
+ $rootScope . $broadcast ( EVENT ) ;
751
+ expect ( spy . callCount ) . toBe ( 1 ) ;
752
+ } ) ) ;
733
753
} ) ;
734
754
735
755
@@ -1114,6 +1134,25 @@ describe('Scope', function() {
1114
1134
child . $broadcast ( 'abc' ) ;
1115
1135
expect ( log ) . toEqual ( '' ) ;
1116
1136
} ) ) ;
1137
+
1138
+
1139
+ it ( 'should increment ancestor $$listenerCount entries' , inject ( function ( $rootScope ) {
1140
+ var child1 = $rootScope . $new ( ) ,
1141
+ child2 = child1 . $new ( ) ,
1142
+ spy = jasmine . createSpy ( ) ;
1143
+
1144
+ $rootScope . $on ( 'event1' , spy ) ;
1145
+ expect ( $rootScope . $$listenerCount ) . toEqual ( { event1 : 1 } ) ;
1146
+
1147
+ child1 . $on ( 'event1' , spy ) ;
1148
+ expect ( $rootScope . $$listenerCount ) . toEqual ( { event1 : 2 } ) ;
1149
+ expect ( child1 . $$listenerCount ) . toEqual ( { event1 : 1 } ) ;
1150
+
1151
+ child2 . $on ( 'event2' , spy ) ;
1152
+ expect ( $rootScope . $$listenerCount ) . toEqual ( { event1 : 2 , event2 : 1 } ) ;
1153
+ expect ( child1 . $$listenerCount ) . toEqual ( { event1 : 1 , event2 : 1 } ) ;
1154
+ expect ( child2 . $$listenerCount ) . toEqual ( { event2 : 1 } ) ;
1155
+ } ) )
1117
1156
} ) ;
1118
1157
1119
1158
@@ -1358,6 +1397,23 @@ describe('Scope', function() {
1358
1397
$rootScope . $broadcast ( 'fooEvent' ) ;
1359
1398
expect ( log ) . toBe ( '' ) ;
1360
1399
} ) ) ;
1400
+
1401
+
1402
+ it ( 'should not descend past scopes with a $$listerCount of 0 or undefined' ,
1403
+ inject ( function ( $rootScope ) {
1404
+ var EVENT = 'fooEvent' ,
1405
+ spy = jasmine . createSpy ( 'listener' ) ;
1406
+
1407
+ // Precondition: There should be no listeners for fooEvent.
1408
+ expect ( $rootScope . $$listenerCount [ EVENT ] ) . toBeUndefined ( ) ;
1409
+
1410
+ // Add a spy listener to a child scope.
1411
+ $rootScope . $$childHead . $$listeners [ EVENT ] = [ spy ] ;
1412
+
1413
+ // $rootScope's count for 'fooEvent' is undefined, so spy should not be called.
1414
+ $rootScope . $broadcast ( EVENT ) ;
1415
+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
1416
+ } ) ) ;
1361
1417
1362
1418
1363
1419
it ( 'should return event object' , function ( ) {
0 commit comments