@@ -4347,6 +4347,40 @@ describe('$compile', function() {
4347
4347
} ) ;
4348
4348
4349
4349
4350
+ it ( 'should not call `$onChanges` twice even when the initial value is `NaN`' , function ( ) {
4351
+ var onChangesSpy = jasmine . createSpy ( '$onChanges' ) ;
4352
+
4353
+ module ( function ( $compileProvider ) {
4354
+ $compileProvider . component ( 'test' , {
4355
+ bindings : { prop : '<' , attr : '@' } ,
4356
+ controller : function TestController ( ) {
4357
+ this . $onChanges = onChangesSpy ;
4358
+ }
4359
+ } ) ;
4360
+ } ) ;
4361
+
4362
+ inject ( function ( $compile , $rootScope ) {
4363
+ var template = '<test prop="a" attr="{{a}}"></test>' +
4364
+ '<test prop="b" attr="{{b}}"></test>' ;
4365
+ $rootScope . a = 'foo' ;
4366
+ $rootScope . b = NaN ;
4367
+
4368
+ element = $compile ( template ) ( $rootScope ) ;
4369
+ $rootScope . $digest ( ) ;
4370
+
4371
+ expect ( onChangesSpy ) . toHaveBeenCalledTimes ( 2 ) ;
4372
+ expect ( onChangesSpy . calls . argsFor ( 0 ) [ 0 ] ) . toEqual ( {
4373
+ prop : jasmine . objectContaining ( { currentValue : 'foo' } ) ,
4374
+ attr : jasmine . objectContaining ( { currentValue : 'foo' } )
4375
+ } ) ;
4376
+ expect ( onChangesSpy . calls . argsFor ( 1 ) [ 0 ] ) . toEqual ( {
4377
+ prop : jasmine . objectContaining ( { currentValue : NaN } ) ,
4378
+ attr : jasmine . objectContaining ( { currentValue : 'NaN' } )
4379
+ } ) ;
4380
+ } ) ;
4381
+ } ) ;
4382
+
4383
+
4350
4384
it ( 'should only trigger one extra digest however many controllers have changes' , function ( ) {
4351
4385
var log = [ ] ;
4352
4386
function TestController1 ( ) { }
@@ -4393,7 +4427,6 @@ describe('$compile', function() {
4393
4427
it ( 'should cope with changes occuring inside `$onChanges()` hooks' , function ( ) {
4394
4428
var log = [ ] ;
4395
4429
function OuterController ( ) { }
4396
-
4397
4430
OuterController . prototype . $onChanges = function ( change ) {
4398
4431
log . push ( [ 'OuterController' , change ] ) ;
4399
4432
// Make a change to the inner component
@@ -4428,7 +4461,6 @@ describe('$compile', function() {
4428
4461
4429
4462
expect ( log ) . toEqual ( [
4430
4463
[ 'OuterController' , { prop1 : jasmine . objectContaining ( { previousValue : undefined , currentValue : 42 } ) } ] ,
4431
- [ 'InnerController' , { prop2 : jasmine . objectContaining ( { previousValue : NaN , currentValue : NaN } ) } ] ,
4432
4464
[ 'InnerController' , { prop2 : jasmine . objectContaining ( { previousValue : NaN , currentValue : 84 } ) } ]
4433
4465
] ) ;
4434
4466
} ) ;
0 commit comments