@@ -323,41 +323,6 @@ describe('Scope', function() {
323
323
} ) ) ;
324
324
325
325
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
-
361
326
it ( 'should allow a watch to be added while in a digest' , inject ( function ( $rootScope ) {
362
327
var watch1 = jasmine . createSpy ( 'watch1' ) ,
363
328
watch2 = jasmine . createSpy ( 'watch2' ) ;
@@ -402,6 +367,47 @@ describe('Scope', function() {
402
367
expect ( log ) . toEqual ( [ ] ) ;
403
368
} ) ) ;
404
369
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
+
405
411
describe ( '$watchCollection' , function ( ) {
406
412
var log , $rootScope , deregister ;
407
413
@@ -1183,7 +1189,7 @@ describe('Scope', function() {
1183
1189
expect ( $rootScope . $$listenerCount ) . toEqual ( { event1 : 2 } ) ;
1184
1190
expect ( child1 . $$listenerCount ) . toEqual ( { event1 : 1 } ) ;
1185
1191
expect ( child2 . $$listenerCount ) . toEqual ( { } ) ;
1186
- } ) )
1192
+ } ) ) ;
1187
1193
} ) ;
1188
1194
} ) ;
1189
1195
0 commit comments