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