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