@@ -4387,6 +4387,40 @@ describe('$compile', function() {
4387
4387
} ) ;
4388
4388
4389
4389
4390
+ it ( 'should not call `$onChanges` twice even when the initial value is `NaN`' , function ( ) {
4391
+ var onChangesSpy = jasmine . createSpy ( '$onChanges' ) ;
4392
+
4393
+ module ( function ( $compileProvider ) {
4394
+ $compileProvider . component ( 'test' , {
4395
+ bindings : { prop : '<' , attr : '@' } ,
4396
+ controller : function TestController ( ) {
4397
+ this . $onChanges = onChangesSpy ;
4398
+ }
4399
+ } ) ;
4400
+ } ) ;
4401
+
4402
+ inject ( function ( $compile , $rootScope ) {
4403
+ var template = '<test prop="a" attr="{{a}}"></test>' +
4404
+ '<test prop="b" attr="{{b}}"></test>' ;
4405
+ $rootScope . a = 'foo' ;
4406
+ $rootScope . b = NaN ;
4407
+
4408
+ element = $compile ( template ) ( $rootScope ) ;
4409
+ $rootScope . $digest ( ) ;
4410
+
4411
+ expect ( onChangesSpy ) . toHaveBeenCalledTimes ( 2 ) ;
4412
+ expect ( onChangesSpy . calls . argsFor ( 0 ) [ 0 ] ) . toEqual ( {
4413
+ prop : jasmine . objectContaining ( { currentValue : 'foo' } ) ,
4414
+ attr : jasmine . objectContaining ( { currentValue : 'foo' } )
4415
+ } ) ;
4416
+ expect ( onChangesSpy . calls . argsFor ( 1 ) [ 0 ] ) . toEqual ( {
4417
+ prop : jasmine . objectContaining ( { currentValue : NaN } ) ,
4418
+ attr : jasmine . objectContaining ( { currentValue : 'NaN' } )
4419
+ } ) ;
4420
+ } ) ;
4421
+ } ) ;
4422
+
4423
+
4390
4424
it ( 'should only trigger one extra digest however many controllers have changes' , function ( ) {
4391
4425
var log = [ ] ;
4392
4426
function TestController1 ( ) { }
@@ -4433,7 +4467,6 @@ describe('$compile', function() {
4433
4467
it ( 'should cope with changes occuring inside `$onChanges()` hooks' , function ( ) {
4434
4468
var log = [ ] ;
4435
4469
function OuterController ( ) { }
4436
-
4437
4470
OuterController . prototype . $onChanges = function ( change ) {
4438
4471
log . push ( [ 'OuterController' , change ] ) ;
4439
4472
// Make a change to the inner component
@@ -4468,7 +4501,6 @@ describe('$compile', function() {
4468
4501
4469
4502
expect ( log ) . toEqual ( [
4470
4503
[ 'OuterController' , { prop1 : jasmine . objectContaining ( { previousValue : undefined , currentValue : 42 } ) } ] ,
4471
- [ 'InnerController' , { prop2 : jasmine . objectContaining ( { previousValue : NaN , currentValue : NaN } ) } ] ,
4472
4504
[ 'InnerController' , { prop2 : jasmine . objectContaining ( { previousValue : NaN , currentValue : 84 } ) } ]
4473
4505
] ) ;
4474
4506
} ) ;
0 commit comments