@@ -2390,6 +2390,45 @@ describe('Scope', function() {
23902390 } ) ) ;
23912391 } ) ;
23922392 } ) ;
2393+
2394+
2395+ it ( 'should allow recursive $emit/$broadcast' , inject ( function ( $rootScope ) {
2396+ var callCount = 0 ;
2397+ $rootScope . $on ( 'evt' , function ( $event , arg0 ) {
2398+ callCount ++ ;
2399+ if ( arg0 !== 1234 ) {
2400+ $rootScope . $emit ( 'evt' , 1234 ) ;
2401+ $rootScope . $broadcast ( 'evt' , 1234 ) ;
2402+ }
2403+ } ) ;
2404+
2405+ $rootScope . $emit ( 'evt' ) ;
2406+ $rootScope . $broadcast ( 'evt' ) ;
2407+ expect ( callCount ) . toBe ( 6 ) ;
2408+ } ) ) ;
2409+
2410+
2411+ it ( 'should allow recursive $emit/$broadcast between parent/child' , inject ( function ( $rootScope ) {
2412+ var child = $rootScope . $new ( ) ;
2413+ var calls = '' ;
2414+
2415+ $rootScope . $on ( 'evt' , function ( $event , arg0 ) {
2416+ calls += 'r' ; // For "root".
2417+ if ( arg0 === 'fromChild' ) {
2418+ $rootScope . $broadcast ( 'evt' , 'fromRoot2' ) ;
2419+ }
2420+ } ) ;
2421+
2422+ child . $on ( 'evt' , function ( $event , arg0 ) {
2423+ calls += 'c' ; // For "child".
2424+ if ( arg0 === 'fromRoot1' ) {
2425+ child . $emit ( 'evt' , 'fromChild' ) ;
2426+ }
2427+ } ) ;
2428+
2429+ $rootScope . $broadcast ( 'evt' , 'fromRoot1' ) ;
2430+ expect ( calls ) . toBe ( 'rccrrc' ) ;
2431+ } ) ) ;
23932432 } ) ;
23942433
23952434 describe ( 'doc examples' , function ( ) {
0 commit comments