@@ -1023,6 +1023,64 @@ describe('parser', function() {
1023
1023
expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
1024
1024
expect ( log ) . toEqual ( '; man' ) ;
1025
1025
} ) ) ;
1026
+
1027
+ describe ( 'literal expressions' , function ( ) {
1028
+ it ( 'should only become stable when all the properties of an object have defined values' , inject ( function ( $parse , $rootScope , log ) {
1029
+ var fn = $parse ( '::{foo: foo, bar: bar}' ) ;
1030
+ $rootScope . $watch ( fn , function ( value ) { log ( value ) ; } , true ) ;
1031
+
1032
+ expect ( log . empty ( ) ) . toEqual ( [ ] ) ;
1033
+ expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
1034
+
1035
+ $rootScope . $digest ( ) ;
1036
+ expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
1037
+ expect ( log . empty ( ) ) . toEqual ( [ { foo : undefined , bar : undefined } ] ) ;
1038
+
1039
+ $rootScope . foo = 'foo' ;
1040
+ $rootScope . $digest ( ) ;
1041
+ expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
1042
+ expect ( log . empty ( ) ) . toEqual ( [ { foo : 'foo' , bar : undefined } ] ) ;
1043
+
1044
+ $rootScope . foo = 'foobar' ;
1045
+ $rootScope . bar = 'bar' ;
1046
+ $rootScope . $digest ( ) ;
1047
+ expect ( $rootScope . $$watchers . length ) . toBe ( 0 ) ;
1048
+ expect ( log . empty ( ) ) . toEqual ( [ { foo : 'foobar' , bar : 'bar' } ] ) ;
1049
+
1050
+ $rootScope . foo = 'baz' ;
1051
+ $rootScope . $digest ( ) ;
1052
+ expect ( $rootScope . $$watchers . length ) . toBe ( 0 ) ;
1053
+ expect ( log . empty ( ) ) . toEqual ( [ ] ) ;
1054
+ } ) ) ;
1055
+
1056
+ it ( 'should only become stable when all the elements of an array have defined values' , inject ( function ( $parse , $rootScope , log ) {
1057
+ var fn = $parse ( '::[foo,bar]' ) ;
1058
+ $rootScope . $watch ( fn , function ( value ) { log ( value ) ; } , true ) ;
1059
+
1060
+ expect ( log . empty ( ) ) . toEqual ( [ ] ) ;
1061
+ expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
1062
+
1063
+ $rootScope . $digest ( ) ;
1064
+ expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
1065
+ expect ( log . empty ( ) ) . toEqual ( [ [ undefined , undefined ] ] ) ;
1066
+
1067
+ $rootScope . foo = 'foo' ;
1068
+ $rootScope . $digest ( ) ;
1069
+ expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
1070
+ expect ( log . empty ( ) ) . toEqual ( [ [ 'foo' , undefined ] ] ) ;
1071
+
1072
+ $rootScope . foo = 'foobar' ;
1073
+ $rootScope . bar = 'bar' ;
1074
+ $rootScope . $digest ( ) ;
1075
+ expect ( $rootScope . $$watchers . length ) . toBe ( 0 ) ;
1076
+ expect ( log . empty ( ) ) . toEqual ( [ [ 'foobar' , 'bar' ] ] ) ;
1077
+
1078
+ $rootScope . foo = 'baz' ;
1079
+ $rootScope . $digest ( ) ;
1080
+ expect ( $rootScope . $$watchers . length ) . toBe ( 0 ) ;
1081
+ expect ( log . empty ( ) ) . toEqual ( [ ] ) ;
1082
+ } ) ) ;
1083
+ } ) ;
1026
1084
} ) ;
1027
1085
1028
1086
describe ( 'locals' , function ( ) {
0 commit comments