@@ -2688,82 +2688,86 @@ describe('parser', function() {
2688
2688
expect ( $parse ( ':: ' ) . literal ) . toBe ( true ) ;
2689
2689
} ) ) ;
2690
2690
2691
- it ( 'should only become stable when all the properties of an object have defined values' , inject ( function ( $parse , $rootScope , log ) {
2692
- var fn = $parse ( '::{foo: foo, bar: bar}' ) ;
2693
- $rootScope . $watch ( fn , function ( value ) { log ( value ) ; } , true ) ;
2694
-
2695
- expect ( log . empty ( ) ) . toEqual ( [ ] ) ;
2696
- expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
2697
-
2698
- $rootScope . $digest ( ) ;
2699
- expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
2700
- expect ( log . empty ( ) ) . toEqual ( [ { foo : undefined , bar : undefined } ] ) ;
2701
-
2702
- $rootScope . foo = 'foo' ;
2703
- $rootScope . $digest ( ) ;
2704
- expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
2705
- expect ( log . empty ( ) ) . toEqual ( [ { foo : 'foo' , bar : undefined } ] ) ;
2706
-
2707
- $rootScope . foo = 'foobar' ;
2708
- $rootScope . bar = 'bar' ;
2709
- $rootScope . $digest ( ) ;
2710
- expect ( $rootScope . $$watchers . length ) . toBe ( 0 ) ;
2711
- expect ( log . empty ( ) ) . toEqual ( [ { foo : 'foobar' , bar : 'bar' } ] ) ;
2712
-
2713
- $rootScope . foo = 'baz' ;
2714
- $rootScope . $digest ( ) ;
2715
- expect ( $rootScope . $$watchers . length ) . toBe ( 0 ) ;
2716
- expect ( log . empty ( ) ) . toEqual ( [ ] ) ;
2717
- } ) ) ;
2718
-
2719
- it ( 'should only become stable when all the elements of an array have defined values' , inject ( function ( $parse , $rootScope , log ) {
2720
- var fn = $parse ( '::[foo,bar]' ) ;
2721
- $rootScope . $watch ( fn , function ( value ) { log ( value ) ; } , true ) ;
2722
-
2723
- expect ( log . empty ( ) ) . toEqual ( [ ] ) ;
2724
- expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
2725
-
2726
- $rootScope . $digest ( ) ;
2727
- expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
2728
- expect ( log . empty ( ) ) . toEqual ( [ [ undefined , undefined ] ] ) ;
2729
-
2730
- $rootScope . foo = 'foo' ;
2731
- $rootScope . $digest ( ) ;
2732
- expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
2733
- expect ( log . empty ( ) ) . toEqual ( [ [ 'foo' , undefined ] ] ) ;
2734
-
2735
- $rootScope . foo = 'foobar' ;
2736
- $rootScope . bar = 'bar' ;
2737
- $rootScope . $digest ( ) ;
2738
- expect ( $rootScope . $$watchers . length ) . toBe ( 0 ) ;
2739
- expect ( log . empty ( ) ) . toEqual ( [ [ 'foobar' , 'bar' ] ] ) ;
2740
-
2741
- $rootScope . foo = 'baz' ;
2742
- $rootScope . $digest ( ) ;
2743
- expect ( $rootScope . $$watchers . length ) . toBe ( 0 ) ;
2744
- expect ( log . empty ( ) ) . toEqual ( [ ] ) ;
2745
- } ) ) ;
2746
-
2747
- it ( 'should only become stable when all the elements of an array have defined values at the end of a $digest' , inject ( function ( $parse , $rootScope , log ) {
2748
- var fn = $parse ( '::[foo]' ) ;
2749
- $rootScope . $watch ( fn , function ( value ) { log ( value ) ; } , true ) ;
2750
- $rootScope . $watch ( 'foo' , function ( ) { if ( $rootScope . foo === 'bar' ) { $rootScope . foo = undefined ; } } ) ;
2751
-
2752
- $rootScope . foo = 'bar' ;
2753
- $rootScope . $digest ( ) ;
2754
- expect ( $rootScope . $$watchers . length ) . toBe ( 2 ) ;
2755
- expect ( log . empty ( ) ) . toEqual ( [ [ 'bar' ] , [ undefined ] ] ) ;
2756
-
2757
- $rootScope . foo = 'baz' ;
2758
- $rootScope . $digest ( ) ;
2759
- expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
2760
- expect ( log . empty ( ) ) . toEqual ( [ [ 'baz' ] ] ) ;
2761
-
2762
- $rootScope . bar = 'qux' ;
2763
- $rootScope . $digest ( ) ;
2764
- expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
2765
- expect ( log ) . toEqual ( [ ] ) ;
2766
- } ) ) ;
2691
+ [ true , false ] . forEach ( function ( isDeep ) {
2692
+ describe ( isDeep ? 'deepWatch' : 'watch' , function ( ) {
2693
+ it ( 'should only become stable when all the properties of an object have defined values' , inject ( function ( $parse , $rootScope , log ) {
2694
+ var fn = $parse ( '::{foo: foo, bar: bar}' ) ;
2695
+ $rootScope . $watch ( fn , function ( value ) { log ( value ) ; } , isDeep ) ;
2696
+
2697
+ expect ( log . empty ( ) ) . toEqual ( [ ] ) ;
2698
+ expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
2699
+
2700
+ $rootScope . $digest ( ) ;
2701
+ expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
2702
+ expect ( log . empty ( ) ) . toEqual ( [ { foo : undefined , bar : undefined } ] ) ;
2703
+
2704
+ $rootScope . foo = 'foo' ;
2705
+ $rootScope . $digest ( ) ;
2706
+ expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
2707
+ expect ( log . empty ( ) ) . toEqual ( [ { foo : 'foo' , bar : undefined } ] ) ;
2708
+
2709
+ $rootScope . foo = 'foobar' ;
2710
+ $rootScope . bar = 'bar' ;
2711
+ $rootScope . $digest ( ) ;
2712
+ expect ( $rootScope . $$watchers . length ) . toBe ( 0 ) ;
2713
+ expect ( log . empty ( ) ) . toEqual ( [ { foo : 'foobar' , bar : 'bar' } ] ) ;
2714
+
2715
+ $rootScope . foo = 'baz' ;
2716
+ $rootScope . $digest ( ) ;
2717
+ expect ( $rootScope . $$watchers . length ) . toBe ( 0 ) ;
2718
+ expect ( log . empty ( ) ) . toEqual ( [ ] ) ;
2719
+ } ) ) ;
2720
+
2721
+ it ( 'should only become stable when all the elements of an array have defined values' , inject ( function ( $parse , $rootScope , log ) {
2722
+ var fn = $parse ( '::[foo,bar]' ) ;
2723
+ $rootScope . $watch ( fn , function ( value ) { log ( value ) ; } , isDeep ) ;
2724
+
2725
+ expect ( log . empty ( ) ) . toEqual ( [ ] ) ;
2726
+ expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
2727
+
2728
+ $rootScope . $digest ( ) ;
2729
+ expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
2730
+ expect ( log . empty ( ) ) . toEqual ( [ [ undefined , undefined ] ] ) ;
2731
+
2732
+ $rootScope . foo = 'foo' ;
2733
+ $rootScope . $digest ( ) ;
2734
+ expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
2735
+ expect ( log . empty ( ) ) . toEqual ( [ [ 'foo' , undefined ] ] ) ;
2736
+
2737
+ $rootScope . foo = 'foobar' ;
2738
+ $rootScope . bar = 'bar' ;
2739
+ $rootScope . $digest ( ) ;
2740
+ expect ( $rootScope . $$watchers . length ) . toBe ( 0 ) ;
2741
+ expect ( log . empty ( ) ) . toEqual ( [ [ 'foobar' , 'bar' ] ] ) ;
2742
+
2743
+ $rootScope . foo = 'baz' ;
2744
+ $rootScope . $digest ( ) ;
2745
+ expect ( $rootScope . $$watchers . length ) . toBe ( 0 ) ;
2746
+ expect ( log . empty ( ) ) . toEqual ( [ ] ) ;
2747
+ } ) ) ;
2748
+
2749
+ it ( 'should only become stable when all the elements of an array have defined values at the end of a $digest' , inject ( function ( $parse , $rootScope , log ) {
2750
+ var fn = $parse ( '::[foo]' ) ;
2751
+ $rootScope . $watch ( fn , function ( value ) { log ( value ) ; } , isDeep ) ;
2752
+ $rootScope . $watch ( 'foo' , function ( ) { if ( $rootScope . foo === 'bar' ) { $rootScope . foo = undefined ; } } ) ;
2753
+
2754
+ $rootScope . foo = 'bar' ;
2755
+ $rootScope . $digest ( ) ;
2756
+ expect ( $rootScope . $$watchers . length ) . toBe ( 2 ) ;
2757
+ expect ( log . empty ( ) ) . toEqual ( [ [ 'bar' ] , [ undefined ] ] ) ;
2758
+
2759
+ $rootScope . foo = 'baz' ;
2760
+ $rootScope . $digest ( ) ;
2761
+ expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
2762
+ expect ( log . empty ( ) ) . toEqual ( [ [ 'baz' ] ] ) ;
2763
+
2764
+ $rootScope . bar = 'qux' ;
2765
+ $rootScope . $digest ( ) ;
2766
+ expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
2767
+ expect ( log ) . toEqual ( [ ] ) ;
2768
+ } ) ) ;
2769
+ } ) ;
2770
+ } ) ;
2767
2771
} ) ;
2768
2772
} ) ;
2769
2773
0 commit comments