@@ -3675,8 +3675,9 @@ describe('$compile', function() {
3675
3675
// Now we should have a single changes entry in the log
3676
3676
expect ( log ) . toEqual ( [
3677
3677
{
3678
- prop1 : { previousValue : undefined , currentValue : 42 } ,
3679
- prop2 : { previousValue : undefined , currentValue : 84 }
3678
+ prop1 : jasmine . objectContaining ( { currentValue : 42 } ) ,
3679
+ prop2 : jasmine . objectContaining ( { currentValue : 84 } ) ,
3680
+ attr : jasmine . objectContaining ( { currentValue : '' } )
3680
3681
}
3681
3682
] ) ;
3682
3683
@@ -3688,8 +3689,8 @@ describe('$compile', function() {
3688
3689
// Now we should have a single changes entry in the log
3689
3690
expect ( log ) . toEqual ( [
3690
3691
{
3691
- prop1 : { previousValue : 42 , currentValue : 17 } ,
3692
- prop2 : { previousValue : 84 , currentValue : 34 }
3692
+ prop1 : jasmine . objectContaining ( { previousValue : 42 , currentValue : 17 } ) ,
3693
+ prop2 : jasmine . objectContaining ( { previousValue : 84 , currentValue : 34 } )
3693
3694
}
3694
3695
] ) ;
3695
3696
@@ -3706,7 +3707,7 @@ describe('$compile', function() {
3706
3707
// onChanges should not have been called
3707
3708
expect ( log ) . toEqual ( [
3708
3709
{
3709
- attr : { previousValue : '' , currentValue : '22' }
3710
+ attr : jasmine . objectContaining ( { previousValue : '' , currentValue : '22' } )
3710
3711
}
3711
3712
] ) ;
3712
3713
} ) ;
@@ -3738,15 +3739,54 @@ describe('$compile', function() {
3738
3739
// Update val to trigger the onChanges
3739
3740
$rootScope . $apply ( 'a = 42' ) ;
3740
3741
// Now the change should have the real previous value (undefined), not the intermediate one (42)
3741
- expect ( log ) . toEqual ( [ { prop : { previousValue : undefined , currentValue : 126 } } ] ) ;
3742
+ expect ( log ) . toEqual ( [ { prop : jasmine . objectContaining ( { currentValue : 126 } ) } ] ) ;
3742
3743
3743
3744
// Clear the log
3744
3745
log = [ ] ;
3745
3746
3746
3747
// Update val to trigger the onChanges
3747
3748
$rootScope . $apply ( 'a = 7' ) ;
3748
3749
// Now the change should have the real previous value (126), not the intermediate one, (91)
3749
- expect ( log ) . toEqual ( [ { prop : { previousValue : 126 , currentValue : 21 } } ] ) ;
3750
+ expect ( log ) . toEqual ( [ { prop : jasmine . objectContaining ( { previousValue : 126 , currentValue : 21 } ) } ] ) ;
3751
+ } ) ;
3752
+ } ) ;
3753
+
3754
+
3755
+ it ( 'should trigger an initial onChanges call for each binding with the `isFirstChange()` returning true' , function ( ) {
3756
+ var log = [ ] ;
3757
+ function TestController ( ) { }
3758
+ TestController . prototype . $onChanges = function ( change ) { log . push ( change ) ; } ;
3759
+
3760
+ angular . module ( 'my' , [ ] )
3761
+ . component ( 'c1' , {
3762
+ controller : TestController ,
3763
+ bindings : { 'prop' : '<' , attr : '@' }
3764
+ } ) ;
3765
+
3766
+ module ( 'my' ) ;
3767
+ inject ( function ( $compile , $rootScope ) {
3768
+ element = $compile ( '<c1 prop="a" attr="{{a}}"></c1>' ) ( $rootScope ) ;
3769
+ expect ( log ) . toEqual ( [ ] ) ;
3770
+ $rootScope . $apply ( 'a = 7' ) ;
3771
+ expect ( log ) . toEqual ( [
3772
+ {
3773
+ prop : jasmine . objectContaining ( { currentValue : 7 } ) ,
3774
+ attr : jasmine . objectContaining ( { currentValue : '7' } )
3775
+ }
3776
+ ] ) ;
3777
+ expect ( log [ 0 ] . prop . isFirstChange ( ) ) . toEqual ( true ) ;
3778
+ expect ( log [ 0 ] . attr . isFirstChange ( ) ) . toEqual ( true ) ;
3779
+
3780
+ log = [ ] ;
3781
+ $rootScope . $apply ( 'a = 9' ) ;
3782
+ expect ( log ) . toEqual ( [
3783
+ {
3784
+ prop : jasmine . objectContaining ( { previousValue : 7 , currentValue : 9 } ) ,
3785
+ attr : jasmine . objectContaining ( { previousValue : '7' , currentValue : '9' } )
3786
+ }
3787
+ ] ) ;
3788
+ expect ( log [ 0 ] . prop . isFirstChange ( ) ) . toEqual ( false ) ;
3789
+ expect ( log [ 0 ] . attr . isFirstChange ( ) ) . toEqual ( false ) ;
3750
3790
} ) ;
3751
3791
} ) ;
3752
3792
@@ -3785,8 +3825,8 @@ describe('$compile', function() {
3785
3825
$rootScope . $apply ( 'val1 = 42; val2 = 17' ) ;
3786
3826
3787
3827
expect ( log ) . toEqual ( [
3788
- [ 'TestController1' , { prop : { previousValue : undefined , currentValue : 42 } } ] ,
3789
- [ 'TestController2' , { prop : { previousValue : undefined , currentValue : 17 } } ]
3828
+ [ 'TestController1' , { prop : jasmine . objectContaining ( { currentValue : 42 } ) } ] ,
3829
+ [ 'TestController2' , { prop : jasmine . objectContaining ( { currentValue : 17 } ) } ]
3790
3830
] ) ;
3791
3831
// A single apply should only trigger three turns of the digest loop
3792
3832
expect ( watchCount ) . toEqual ( 3 ) ;
@@ -3830,8 +3870,9 @@ describe('$compile', function() {
3830
3870
$rootScope . $apply ( 'a = 42' ) ;
3831
3871
3832
3872
expect ( log ) . toEqual ( [
3833
- [ 'OuterController' , { prop1 : { previousValue : undefined , currentValue : 42 } } ] ,
3834
- [ 'InnerController' , { prop2 : { previousValue : undefined , currentValue : 72 } } ]
3873
+ [ 'OuterController' , { prop1 : jasmine . objectContaining ( { currentValue : 42 } ) } ] ,
3874
+ [ 'InnerController' , { prop2 : jasmine . objectContaining ( { currentValue : undefined } ) } ] ,
3875
+ [ 'InnerController' , { prop2 : jasmine . objectContaining ( { currentValue : 72 } ) } ]
3835
3876
] ) ;
3836
3877
} ) ;
3837
3878
} ) ;
0 commit comments