aboutsummaryrefslogtreecommitdiffstats
path: root/test/ng/rootScopeSpec.js
diff options
context:
space:
mode:
authorIgor Minar2014-01-02 13:28:30 -0800
committerIgor Minar2014-01-02 15:28:56 -0800
commit010413f90a9352a5aab1e7517a58eab5f30f2b06 (patch)
tree85b9b737b639cced840438d68275c6b7b330647b /test/ng/rootScopeSpec.js
parent4f57236614415eea919221ea5f99c4d8689b3267 (diff)
downloadangular.js-010413f90a9352a5aab1e7517a58eab5f30f2b06.tar.bz2
test(rootScope): reorganize $watch deregistration specs into a describe
Diffstat (limited to 'test/ng/rootScopeSpec.js')
-rw-r--r--test/ng/rootScopeSpec.js78
1 files 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({});
- }))
+ }));
});
});