From 010413f90a9352a5aab1e7517a58eab5f30f2b06 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Thu, 2 Jan 2014 13:28:30 -0800 Subject: test(rootScope): reorganize $watch deregistration specs into a describe --- test/ng/rootScopeSpec.js | 78 ++++++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 36 deletions(-) diff --git a/test/ng/rootScopeSpec.js b/test/ng/rootScopeSpec.js index 3677ccc8..78cf9aa5 100644 --- a/test/ng/rootScopeSpec.js +++ b/test/ng/rootScopeSpec.js @@ -323,41 +323,6 @@ describe('Scope', function() { })); - it('should return a function that allows listeners to be unregistered', inject( - function($rootScope) { - var listener = jasmine.createSpy('watch listener'), - listenerRemove; - - listenerRemove = $rootScope.$watch('foo', listener); - $rootScope.$digest(); //init - expect(listener).toHaveBeenCalled(); - expect(listenerRemove).toBeDefined(); - - listener.reset(); - $rootScope.foo = 'bar'; - $rootScope.$digest(); //triger - expect(listener).toHaveBeenCalledOnce(); - - listener.reset(); - $rootScope.foo = 'baz'; - listenerRemove(); - $rootScope.$digest(); //trigger - expect(listener).not.toHaveBeenCalled(); - })); - - it('should allow a watch to be unregistered while in a digest', inject(function($rootScope) { - var remove1, remove2; - $rootScope.$watch('remove', function() { - remove1(); - remove2(); - }); - remove1 = $rootScope.$watch('thing', function() {}); - remove2 = $rootScope.$watch('thing', function() {}); - expect(function() { - $rootScope.$apply('remove = true'); - }).not.toThrow(); - })); - it('should allow a watch to be added while in a digest', inject(function($rootScope) { var watch1 = jasmine.createSpy('watch1'), watch2 = jasmine.createSpy('watch2'); @@ -402,6 +367,47 @@ describe('Scope', function() { expect(log).toEqual([]); })); + + describe('$watch deregistration', function() { + + it('should return a function that allows listeners to be deregistered', inject( + function($rootScope) { + var listener = jasmine.createSpy('watch listener'), + listenerRemove; + + listenerRemove = $rootScope.$watch('foo', listener); + $rootScope.$digest(); //init + expect(listener).toHaveBeenCalled(); + expect(listenerRemove).toBeDefined(); + + listener.reset(); + $rootScope.foo = 'bar'; + $rootScope.$digest(); //triger + expect(listener).toHaveBeenCalledOnce(); + + listener.reset(); + $rootScope.foo = 'baz'; + listenerRemove(); + $rootScope.$digest(); //trigger + expect(listener).not.toHaveBeenCalled(); + })); + + + it('should allow a watch to be deregistered while in a digest', inject(function($rootScope) { + var remove1, remove2; + $rootScope.$watch('remove', function() { + remove1(); + remove2(); + }); + remove1 = $rootScope.$watch('thing', function() {}); + remove2 = $rootScope.$watch('thing', function() {}); + expect(function() { + $rootScope.$apply('remove = true'); + }).not.toThrow(); + })); + }); + + describe('$watchCollection', function() { var log, $rootScope, deregister; @@ -1183,7 +1189,7 @@ describe('Scope', function() { expect($rootScope.$$listenerCount).toEqual({event1: 2}); expect(child1.$$listenerCount).toEqual({event1: 1}); expect(child2.$$listenerCount).toEqual({}); - })) + })); }); }); -- cgit v1.2.3 ef='#n21'>21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36