@@ -844,59 +844,80 @@ describe('Scope', function() {
844
844
} ) ) ;
845
845
846
846
847
- it ( 'should work for a group with just a single expression' , function ( ) {
848
- scope . $watchGroup ( [ 'a' ] , function ( values , oldValues , s ) {
847
+ it ( 'should detect a change to any one expression in the group ' , function ( ) {
848
+ scope . $watchGroup ( [ 'a' , 'b' ] , function ( values , oldValues , s ) {
849
849
expect ( s ) . toBe ( scope ) ;
850
850
log ( oldValues + ' >>> ' + values ) ;
851
851
} ) ;
852
852
853
853
scope . a = 'foo' ;
854
+ scope . b = 'bar' ;
854
855
scope . $digest ( ) ;
855
- expect ( log ) . toEqual ( 'foo >>> foo' ) ;
856
+ expect ( log ) . toEqual ( 'foo,bar >>> foo,bar ' ) ;
856
857
857
858
log . reset ( ) ;
858
859
scope . $digest ( ) ;
859
860
expect ( log ) . toEqual ( '' ) ;
860
861
861
- scope . a = 'bar ' ;
862
+ scope . a = 'a ' ;
862
863
scope . $digest ( ) ;
863
- expect ( log ) . toEqual ( 'foo >>> bar' ) ;
864
+ expect ( log ) . toEqual ( 'foo,bar >>> a,bar' ) ;
865
+
866
+ log . reset ( ) ;
867
+ scope . a = 'A' ;
868
+ scope . b = 'B' ;
869
+ scope . $digest ( ) ;
870
+ expect ( log ) . toEqual ( 'a,bar >>> A,B' ) ;
864
871
} ) ;
865
872
866
873
867
- it ( 'should detect a change to any one expression in the group ' , function ( ) {
868
- scope . $watchGroup ( [ 'a' , 'b' ] , function ( values , oldValues , s ) {
874
+ it ( 'should work for a group with just a single expression ' , function ( ) {
875
+ scope . $watchGroup ( [ 'a' ] , function ( values , oldValues , s ) {
869
876
expect ( s ) . toBe ( scope ) ;
870
877
log ( oldValues + ' >>> ' + values ) ;
871
878
} ) ;
872
879
873
880
scope . a = 'foo' ;
874
- scope . b = 'bar' ;
875
881
scope . $digest ( ) ;
876
- expect ( log ) . toEqual ( 'foo,bar >>> foo,bar ' ) ;
882
+ expect ( log ) . toEqual ( 'foo >>> foo' ) ;
877
883
878
884
log . reset ( ) ;
879
885
scope . $digest ( ) ;
880
886
expect ( log ) . toEqual ( '' ) ;
881
887
882
- scope . a = 'a ' ;
888
+ scope . a = 'bar ' ;
883
889
scope . $digest ( ) ;
884
- expect ( log ) . toEqual ( 'foo,bar >>> a,bar' ) ;
890
+ expect ( log ) . toEqual ( 'foo >>> bar' ) ;
891
+ } ) ;
892
+
893
+
894
+ it ( 'should call the listener once when the array of watchExpressions is empty' , function ( ) {
895
+ scope . $watchGroup ( [ ] , function ( values , oldValues ) {
896
+ log ( oldValues + ' >>> ' + values ) ;
897
+ } ) ;
898
+
899
+ expect ( log ) . toEqual ( '' ) ;
900
+ scope . $digest ( ) ;
901
+ expect ( log ) . toEqual ( ' >>> ' ) ;
885
902
886
903
log . reset ( ) ;
887
- scope . a = 'A' ;
888
- scope . b = 'B' ;
889
904
scope . $digest ( ) ;
890
- expect ( log ) . toEqual ( 'a,bar >>> A,B ' ) ;
905
+ expect ( log ) . toEqual ( '' ) ;
891
906
} ) ;
892
907
893
908
894
909
it ( 'should not call watch action fn when watchGroup was deregistered' , function ( ) {
895
- var deregister = scope . $watchGroup ( [ 'a' , 'b' ] , function ( values , oldValues ) {
910
+ var deregisterMany = scope . $watchGroup ( [ 'a' , 'b' ] , function ( values , oldValues ) {
911
+ log ( oldValues + ' >>> ' + values ) ;
912
+ } ) , deregisterOne = scope . $watchGroup ( [ 'a' ] , function ( values , oldValues ) {
913
+ log ( oldValues + ' >>> ' + values ) ;
914
+ } ) , deregisterNone = scope . $watchGroup ( [ ] , function ( values , oldValues ) {
896
915
log ( oldValues + ' >>> ' + values ) ;
897
916
} ) ;
898
917
899
- deregister ( ) ;
918
+ deregisterMany ( ) ;
919
+ deregisterOne ( ) ;
920
+ deregisterNone ( ) ;
900
921
scope . a = 'xxx' ;
901
922
scope . b = 'yyy' ;
902
923
scope . $digest ( ) ;
0 commit comments