Repository: angular/angular.js
File: test/ng/rootScopeSpec.js (JavaScript)

Code before:
          var listener1 = jasmine.createSpy().and.callFake(function() { remove1(); });
          var remove1 = $rootScope.$on('abc', listener1);

          var listener2 = jasmine.createSpy();
          var remove2 = $rootScope.$on('abc', listener2);

          var listener3 = jasmine.createSpy();
          var remove3 = $rootScope.$on('abc', listener3);

          $rootScope.$broadcast('abc');
          expect(listener1).toHaveBeenCalled();
          expect(listener2).toHaveBeenCalled();
          expect(listener3).toHaveBeenCalled();

          listener1.calls.reset();
          listener2.calls.reset();
          listener3.calls.reset();

          $rootScope.$broadcast('abc');
          expect(listener1).not.toHaveBeenCalled();
          expect(listener2).toHaveBeenCalled();
          expect(listener3).toHaveBeenCalled();
        }));


        it('should call all listeners when removing previous', inject(function($rootScope) {
          var listener1 = jasmine.createSpy();
          var remove1 = $rootScope.$on('abc', listener1);

          var listener2 = jasmine.createSpy().and.callFake(remove1);
          var remove2 = $rootScope.$on('abc', listener2);

          var listener3 = jasmine.createSpy();
          var remove3 = $rootScope.$on('abc', listener3);

          $rootScope.$broadcast('abc');
          expect(listener1).toHaveBeenCalled();
          expect(listener2).toHaveBeenCalled();
          expect(listener3).toHaveBeenCalled();

          listener1.calls.reset();
          listener2.calls.reset();
          listener3.calls.reset();

          $rootScope.$broadcast('abc');
          expect(listener1).not.toHaveBeenCalled();
          expect(listener2).toHaveBeenCalled();
          expect(listener3).toHaveBeenCalled();
        }));



Review comment (suggestion):
```
should call all subsequent listeners when a previous listener is removed via a handler
```

Code after:
          var listener1 = jasmine.createSpy('listener1').and.callFake(function() { remove1(); });
          var remove1 = $rootScope.$on('abc', listener1);

          var listener2 = jasmine.createSpy('listener2');
          var remove2 = $rootScope.$on('abc', listener2);

          var listener3 = jasmine.createSpy('listener3');
          var remove3 = $rootScope.$on('abc', listener3);

          $rootScope.$broadcast('abc');
          expect(listener1).toHaveBeenCalled();
          expect(listener2).toHaveBeenCalled();
          expect(listener3).toHaveBeenCalled();

          listener1.calls.reset();
          listener2.calls.reset();
          listener3.calls.reset();

          $rootScope.$broadcast('abc');
          expect(listener1).not.toHaveBeenCalled();
          expect(listener2).toHaveBeenCalled();
          expect(listener3).toHaveBeenCalled();
        }));


        it('should call all subsequent listeners when a previous listener is removed via a handler', inject(function($rootScope) {
          var listener1 = jasmine.createSpy();
          var remove1 = $rootScope.$on('abc', listener1);

          var listener2 = jasmine.createSpy().and.callFake(remove1);
          var remove2 = $rootScope.$on('abc', listener2);

          var listener3 = jasmine.createSpy();
          var remove3 = $rootScope.$on('abc', listener3);

          $rootScope.$broadcast('abc');
          expect(listener1).toHaveBeenCalled();
          expect(listener2).toHaveBeenCalled();
          expect(listener3).toHaveBeenCalled();

          listener1.calls.reset();
          listener2.calls.reset();
          listener3.calls.reset();

          $rootScope.$broadcast('abc');
          expect(listener1).not.toHaveBeenCalled();
          expect(listener2).toHaveBeenCalled();
          expect(listener3).toHaveBeenCalled();
        }));