diff --git a/test/ng/rootScopeSpec.js b/test/ng/rootScopeSpec.js index 92e713a5b99e..bd157467b092 100644 --- a/test/ng/rootScopeSpec.js +++ b/test/ng/rootScopeSpec.js @@ -2316,6 +2316,84 @@ describe('Scope', function() { })); + it('should call next listener when removing current', inject(function($rootScope) { + 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(); + })); + + + it('should not call listener when removed by previous', inject(function($rootScope) { + var listener1 = jasmine.createSpy(); + var remove1 = $rootScope.$on('abc', listener1); + + var listener2 = jasmine.createSpy().and.callFake(function() { remove3(); }); + 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).not.toHaveBeenCalled(); + + listener1.calls.reset(); + listener2.calls.reset(); + listener3.calls.reset(); + + $rootScope.$broadcast('abc'); + expect(listener1).toHaveBeenCalled(); + expect(listener2).toHaveBeenCalled(); + expect(listener3).not.toHaveBeenCalled(); + })); + + it('should decrement ancestor $$listenerCount entries', inject(function($rootScope) { var child1 = $rootScope.$new(), child2 = child1.$new(),