@@ -1174,6 +1174,64 @@ describe('parser', function() {
11741174 $rootScope . $digest ( ) ;
11751175 expect ( fn ( ) ) . toEqual ( null ) ;
11761176 } ) ) ;
1177+
1178+ describe ( 'literal expressions' , function ( ) {
1179+ it ( 'should only become stable when all the properties of an object have defined values' , inject ( function ( $parse , $rootScope , log ) {
1180+ var fn = $parse ( '::{foo: foo, bar: bar}' ) ;
1181+ $rootScope . $watch ( fn , function ( value ) { log ( value ) ; } , true ) ;
1182+
1183+ expect ( log . empty ( ) ) . toEqual ( [ ] ) ;
1184+ expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
1185+
1186+ $rootScope . $digest ( ) ;
1187+ expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
1188+ expect ( log . empty ( ) ) . toEqual ( [ { foo : undefined , bar : undefined } ] ) ;
1189+
1190+ $rootScope . foo = 'foo' ;
1191+ $rootScope . $digest ( ) ;
1192+ expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
1193+ expect ( log . empty ( ) ) . toEqual ( [ { foo : 'foo' , bar : undefined } ] ) ;
1194+
1195+ $rootScope . foo = 'foobar' ;
1196+ $rootScope . bar = 'bar' ;
1197+ $rootScope . $digest ( ) ;
1198+ expect ( $rootScope . $$watchers . length ) . toBe ( 0 ) ;
1199+ expect ( log . empty ( ) ) . toEqual ( [ { foo : 'foobar' , bar : 'bar' } ] ) ;
1200+
1201+ $rootScope . foo = 'baz' ;
1202+ $rootScope . $digest ( ) ;
1203+ expect ( $rootScope . $$watchers . length ) . toBe ( 0 ) ;
1204+ expect ( log . empty ( ) ) . toEqual ( [ ] ) ;
1205+ } ) ) ;
1206+
1207+ it ( 'should only become stable when all the elements of an array have defined values' , inject ( function ( $parse , $rootScope , log ) {
1208+ var fn = $parse ( '::[foo,bar]' ) ;
1209+ $rootScope . $watch ( fn , function ( value ) { log ( value ) ; } , true ) ;
1210+
1211+ expect ( log . empty ( ) ) . toEqual ( [ ] ) ;
1212+ expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
1213+
1214+ $rootScope . $digest ( ) ;
1215+ expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
1216+ expect ( log . empty ( ) ) . toEqual ( [ [ undefined , undefined ] ] ) ;
1217+
1218+ $rootScope . foo = 'foo' ;
1219+ $rootScope . $digest ( ) ;
1220+ expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
1221+ expect ( log . empty ( ) ) . toEqual ( [ [ 'foo' , undefined ] ] ) ;
1222+
1223+ $rootScope . foo = 'foobar' ;
1224+ $rootScope . bar = 'bar' ;
1225+ $rootScope . $digest ( ) ;
1226+ expect ( $rootScope . $$watchers . length ) . toBe ( 0 ) ;
1227+ expect ( log . empty ( ) ) . toEqual ( [ [ 'foobar' , 'bar' ] ] ) ;
1228+
1229+ $rootScope . foo = 'baz' ;
1230+ $rootScope . $digest ( ) ;
1231+ expect ( $rootScope . $$watchers . length ) . toBe ( 0 ) ;
1232+ expect ( log . empty ( ) ) . toEqual ( [ ] ) ;
1233+ } ) ) ;
1234+ } ) ;
11771235 } ) ;
11781236
11791237 describe ( 'locals' , function ( ) {
0 commit comments