aboutsummaryrefslogtreecommitdiffstats
path: root/test/ng/rootScopeSpec.js
diff options
context:
space:
mode:
authorPaulo Scardine2013-06-09 23:16:26 -0300
committerPete Bacon Darwin2013-07-11 22:04:00 +0100
commit8bd6619b7efa485b020fec96c76047e480469871 (patch)
tree00bfe8e71844a17d5ac384926fa39eb826ffc082 /test/ng/rootScopeSpec.js
parent4e96334b5c2a18204cd82fa121e2290906277b39 (diff)
downloadangular.js-8bd6619b7efa485b020fec96c76047e480469871.tar.bz2
fix(scope): watches can be safely unregistered inside watch handlers
Closes #2915
Diffstat (limited to 'test/ng/rootScopeSpec.js')
-rw-r--r--test/ng/rootScopeSpec.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/ng/rootScopeSpec.js b/test/ng/rootScopeSpec.js
index 9d86c098..15990c96 100644
--- a/test/ng/rootScopeSpec.js
+++ b/test/ng/rootScopeSpec.js
@@ -330,6 +330,30 @@ describe('Scope', function() {
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');
+ $rootScope.$watch('foo', function() {
+ $rootScope.$watch('foo', watch1);
+ $rootScope.$watch('foo', watch2);
+ });
+ $rootScope.$apply('foo = true');
+ expect(watch1).toHaveBeenCalled();
+ expect(watch2).toHaveBeenCalled();
+ }));
it('should not infinitely digest when current value is NaN', inject(function($rootScope) {
$rootScope.$watch(function() { return NaN;});