Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 010413f

Browse files
committed
test(rootScope): reorganize $watch deregistration specs into a describe
1 parent 4f57236 commit 010413f

File tree

1 file changed

+42
-36
lines changed

1 file changed

+42
-36
lines changed

test/ng/rootScopeSpec.js

+42-36
Original file line numberDiff line numberDiff line change
@@ -323,41 +323,6 @@ describe('Scope', function() {
323323
}));
324324

325325

326-
it('should return a function that allows listeners to be unregistered', inject(
327-
function($rootScope) {
328-
var listener = jasmine.createSpy('watch listener'),
329-
listenerRemove;
330-
331-
listenerRemove = $rootScope.$watch('foo', listener);
332-
$rootScope.$digest(); //init
333-
expect(listener).toHaveBeenCalled();
334-
expect(listenerRemove).toBeDefined();
335-
336-
listener.reset();
337-
$rootScope.foo = 'bar';
338-
$rootScope.$digest(); //triger
339-
expect(listener).toHaveBeenCalledOnce();
340-
341-
listener.reset();
342-
$rootScope.foo = 'baz';
343-
listenerRemove();
344-
$rootScope.$digest(); //trigger
345-
expect(listener).not.toHaveBeenCalled();
346-
}));
347-
348-
it('should allow a watch to be unregistered while in a digest', inject(function($rootScope) {
349-
var remove1, remove2;
350-
$rootScope.$watch('remove', function() {
351-
remove1();
352-
remove2();
353-
});
354-
remove1 = $rootScope.$watch('thing', function() {});
355-
remove2 = $rootScope.$watch('thing', function() {});
356-
expect(function() {
357-
$rootScope.$apply('remove = true');
358-
}).not.toThrow();
359-
}));
360-
361326
it('should allow a watch to be added while in a digest', inject(function($rootScope) {
362327
var watch1 = jasmine.createSpy('watch1'),
363328
watch2 = jasmine.createSpy('watch2');
@@ -402,6 +367,47 @@ describe('Scope', function() {
402367
expect(log).toEqual([]);
403368
}));
404369

370+
371+
describe('$watch deregistration', function() {
372+
373+
it('should return a function that allows listeners to be deregistered', inject(
374+
function($rootScope) {
375+
var listener = jasmine.createSpy('watch listener'),
376+
listenerRemove;
377+
378+
listenerRemove = $rootScope.$watch('foo', listener);
379+
$rootScope.$digest(); //init
380+
expect(listener).toHaveBeenCalled();
381+
expect(listenerRemove).toBeDefined();
382+
383+
listener.reset();
384+
$rootScope.foo = 'bar';
385+
$rootScope.$digest(); //triger
386+
expect(listener).toHaveBeenCalledOnce();
387+
388+
listener.reset();
389+
$rootScope.foo = 'baz';
390+
listenerRemove();
391+
$rootScope.$digest(); //trigger
392+
expect(listener).not.toHaveBeenCalled();
393+
}));
394+
395+
396+
it('should allow a watch to be deregistered while in a digest', inject(function($rootScope) {
397+
var remove1, remove2;
398+
$rootScope.$watch('remove', function() {
399+
remove1();
400+
remove2();
401+
});
402+
remove1 = $rootScope.$watch('thing', function() {});
403+
remove2 = $rootScope.$watch('thing', function() {});
404+
expect(function() {
405+
$rootScope.$apply('remove = true');
406+
}).not.toThrow();
407+
}));
408+
});
409+
410+
405411
describe('$watchCollection', function() {
406412
var log, $rootScope, deregister;
407413

@@ -1183,7 +1189,7 @@ describe('Scope', function() {
11831189
expect($rootScope.$$listenerCount).toEqual({event1: 2});
11841190
expect(child1.$$listenerCount).toEqual({event1: 1});
11851191
expect(child2.$$listenerCount).toEqual({});
1186-
}))
1192+
}));
11871193
});
11881194
});
11891195

0 commit comments

Comments
 (0)