@@ -4259,6 +4259,78 @@ describe('$compile', function() {
4259
4259
} ) ;
4260
4260
4261
4261
4262
+ it ( 'should trigger `$onChanges` for literal expressions when expression input value changes (simple value)' , function ( ) {
4263
+ var log = [ ] ;
4264
+ function TestController ( ) { }
4265
+ TestController . prototype . $onChanges = function ( change ) { log . push ( change ) ; } ;
4266
+
4267
+ angular . module ( 'my' , [ ] )
4268
+ . component ( 'c1' , {
4269
+ controller : TestController ,
4270
+ bindings : { 'prop1' : '<' }
4271
+ } ) ;
4272
+
4273
+ module ( 'my' ) ;
4274
+ inject ( function ( $compile , $rootScope ) {
4275
+ element = $compile ( '<c1 prop1="[val]"></c1>' ) ( $rootScope ) ;
4276
+
4277
+ $rootScope . $apply ( 'val = 1' ) ;
4278
+ expect ( log . pop ( ) ) . toEqual ( { prop1 : jasmine . objectContaining ( { previousValue : [ undefined ] , currentValue : [ 1 ] } ) } ) ;
4279
+
4280
+ $rootScope . $apply ( 'val = 2' ) ;
4281
+ expect ( log . pop ( ) ) . toEqual ( { prop1 : jasmine . objectContaining ( { previousValue : [ 1 ] , currentValue : [ 2 ] } ) } ) ;
4282
+ } ) ;
4283
+ } ) ;
4284
+
4285
+
4286
+ it ( 'should trigger `$onChanges` for literal expressions when expression input value changes (complex value)' , function ( ) {
4287
+ var log = [ ] ;
4288
+ function TestController ( ) { }
4289
+ TestController . prototype . $onChanges = function ( change ) { log . push ( change ) ; } ;
4290
+
4291
+ angular . module ( 'my' , [ ] )
4292
+ . component ( 'c1' , {
4293
+ controller : TestController ,
4294
+ bindings : { 'prop1' : '<' }
4295
+ } ) ;
4296
+
4297
+ module ( 'my' ) ;
4298
+ inject ( function ( $compile , $rootScope ) {
4299
+ element = $compile ( '<c1 prop1="[val]"></c1>' ) ( $rootScope ) ;
4300
+
4301
+ $rootScope . $apply ( 'val = [1]' ) ;
4302
+ expect ( log . pop ( ) ) . toEqual ( { prop1 : jasmine . objectContaining ( { previousValue : [ undefined ] , currentValue : [ [ 1 ] ] } ) } ) ;
4303
+
4304
+ $rootScope . $apply ( 'val = [2]' ) ;
4305
+ expect ( log . pop ( ) ) . toEqual ( { prop1 : jasmine . objectContaining ( { previousValue : [ [ 1 ] ] , currentValue : [ [ 2 ] ] } ) } ) ;
4306
+ } ) ;
4307
+ } ) ;
4308
+
4309
+
4310
+ it ( 'should trigger `$onChanges` for literal expressions when expression input value changes instances, even when equal' , function ( ) {
4311
+ var log = [ ] ;
4312
+ function TestController ( ) { }
4313
+ TestController . prototype . $onChanges = function ( change ) { log . push ( change ) ; } ;
4314
+
4315
+ angular . module ( 'my' , [ ] )
4316
+ . component ( 'c1' , {
4317
+ controller : TestController ,
4318
+ bindings : { 'prop1' : '<' }
4319
+ } ) ;
4320
+
4321
+ module ( 'my' ) ;
4322
+ inject ( function ( $compile , $rootScope ) {
4323
+ element = $compile ( '<c1 prop1="[val]"></c1>' ) ( $rootScope ) ;
4324
+
4325
+ $rootScope . $apply ( 'val = [1]' ) ;
4326
+ expect ( log . pop ( ) ) . toEqual ( { prop1 : jasmine . objectContaining ( { previousValue : [ undefined ] , currentValue : [ [ 1 ] ] } ) } ) ;
4327
+
4328
+ $rootScope . $apply ( 'val = [1]' ) ;
4329
+ expect ( log . pop ( ) ) . toEqual ( { prop1 : jasmine . objectContaining ( { previousValue : [ [ 1 ] ] , currentValue : [ [ 1 ] ] } ) } ) ;
4330
+ } ) ;
4331
+ } ) ;
4332
+
4333
+
4262
4334
it ( 'should pass the original value as `previousValue` even if there were multiple changes in a single digest' , function ( ) {
4263
4335
var log = [ ] ;
4264
4336
function TestController ( ) { }
0 commit comments