@@ -3686,12 +3686,16 @@ describe('$compile', function() {
3686
3686
$rootScope . $watch ( 'val' , function ( val , oldVal ) { $rootScope . val2 = val * 2 ; } ) ;
3687
3687
// Setup the directive with two bindings
3688
3688
element = $compile ( '<c1 prop1="val" prop2="val2" other="val3" attr="{{val4}}"></c1>' ) ( $rootScope ) ;
3689
+ $rootScope . $apply ( ) ;
3689
3690
3690
3691
expect ( log ) . toEqual ( [
3691
3692
{
3692
3693
prop1 : jasmine . objectContaining ( { currentValue : undefined } ) ,
3693
3694
prop2 : jasmine . objectContaining ( { currentValue : undefined } ) ,
3694
3695
attr : jasmine . objectContaining ( { currentValue : '' } )
3696
+ } ,
3697
+ {
3698
+ prop2 : jasmine . objectContaining ( { currentValue : NaN } )
3695
3699
}
3696
3700
] ) ;
3697
3701
@@ -3756,6 +3760,7 @@ describe('$compile', function() {
3756
3760
module ( 'my' ) ;
3757
3761
inject ( function ( $compile , $rootScope ) {
3758
3762
element = $compile ( '<c1 prop1="val"></c1>' ) ( $rootScope ) ;
3763
+ $rootScope . $apply ( ) ;
3759
3764
3760
3765
$rootScope . $apply ( 'val = 1' ) ;
3761
3766
expect ( log . pop ( ) ) . toEqual ( { prop1 : jasmine . objectContaining ( { previousValue : undefined , currentValue : 1 } ) } ) ;
@@ -3823,6 +3828,8 @@ describe('$compile', function() {
3823
3828
3824
3829
$rootScope . $apply ( 'a = 7' ) ;
3825
3830
element = $compile ( '<c1 prop="a" attr="{{a}}"></c1>' ) ( $rootScope ) ;
3831
+ $rootScope . $apply ( ) ;
3832
+
3826
3833
expect ( log ) . toEqual ( [
3827
3834
{
3828
3835
prop : jasmine . objectContaining ( { currentValue : 7 } ) ,
@@ -3862,6 +3869,8 @@ describe('$compile', function() {
3862
3869
inject ( function ( $compile , $rootScope ) {
3863
3870
$rootScope . $apply ( 'a = 7' ) ;
3864
3871
element = $compile ( '<c1 prop="a" attr="{{a}}"></c1>' ) ( $rootScope ) ;
3872
+ $rootScope . $apply ( ) ;
3873
+
3865
3874
expect ( log ) . toEqual ( [
3866
3875
{
3867
3876
prop : jasmine . objectContaining ( { currentValue : 7 } ) ,
@@ -3911,8 +3920,10 @@ describe('$compile', function() {
3911
3920
3912
3921
// Setup two sibling components with bindings that will change
3913
3922
element = $compile ( '<div><c1 prop="val1"></c1><c2 prop="val2"></c2></div>' ) ( $rootScope ) ;
3923
+ $rootScope . $apply ( ) ;
3914
3924
3915
3925
// Clear out initial changes
3926
+ watchCount = 0 ;
3916
3927
log = [ ] ;
3917
3928
3918
3929
// Update val to trigger the onChanges
@@ -3958,6 +3969,7 @@ describe('$compile', function() {
3958
3969
3959
3970
// Setup the directive with two bindings
3960
3971
element = $compile ( '<outer prop1="a"></outer>' ) ( $rootScope ) ;
3972
+ $rootScope . $apply ( ) ;
3961
3973
3962
3974
// Clear out initial changes
3963
3975
log = [ ] ;
@@ -3990,6 +4002,7 @@ describe('$compile', function() {
3990
4002
3991
4003
// Setup the directive with bindings that will keep updating the bound value forever
3992
4004
element = $compile ( '<c1 prop="a" on-change="a = -a"></c1>' ) ( $rootScope ) ;
4005
+ $rootScope . $apply ( ) ;
3993
4006
3994
4007
// Update val to trigger the unstable onChanges, which will result in an error
3995
4008
expect ( function ( ) {
@@ -4025,6 +4038,7 @@ describe('$compile', function() {
4025
4038
4026
4039
// Setup the directive with bindings that will keep updating the bound value forever
4027
4040
element = $compile ( '<c1 prop="a" on-change="a = -a"></c1>' ) ( $rootScope ) ;
4041
+ $rootScope . $apply ( ) ;
4028
4042
4029
4043
// Update val to trigger the unstable onChanges, which will result in an error
4030
4044
$rootScope . $apply ( 'a = 42' ) ;
@@ -4744,6 +4758,8 @@ describe('$compile', function() {
4744
4758
describe ( 'one-way binding' , function ( ) {
4745
4759
it ( 'should update isolate when the identity of origin changes' , inject ( function ( ) {
4746
4760
compile ( '<div><span my-component ow-ref="obj">' ) ;
4761
+ $rootScope . $apply ( ) ;
4762
+
4747
4763
expect ( componentScope . owRef ) . toBeUndefined ( ) ;
4748
4764
expect ( componentScope . owRefAlias ) . toBe ( componentScope . owRef ) ;
4749
4765
@@ -4780,6 +4796,8 @@ describe('$compile', function() {
4780
4796
4781
4797
it ( 'should update isolate when both change' , inject ( function ( ) {
4782
4798
compile ( '<div><span my-component ow-ref="name">' ) ;
4799
+ $rootScope . $apply ( ) ;
4800
+
4783
4801
$rootScope . name = { mark :123 } ;
4784
4802
componentScope . owRef = 'misko' ;
4785
4803
@@ -4796,6 +4814,35 @@ describe('$compile', function() {
4796
4814
expect ( componentScope . owRefAlias ) . toBe ( $rootScope . name ) ;
4797
4815
} ) ) ;
4798
4816
4817
+ it ( 'should not update isolate again after $onInit if outer has not changed' , function ( ) {
4818
+ var log = [ ] ;
4819
+ var component ;
4820
+ angular . module ( 'owComponentTest' , [ ] )
4821
+ . component ( 'owComponent' , {
4822
+ bindings : { input : '<' } ,
4823
+ controller : function ( ) {
4824
+ component = this ;
4825
+ this . input = 'constructor' ;
4826
+ this . $onInit = function ( ) {
4827
+ this . input = '$onInit' ;
4828
+ } ;
4829
+ this . $onChanges = function ( changes ) {
4830
+ if ( changes . input ) {
4831
+ log . push ( changes . input ) ;
4832
+ }
4833
+ } ;
4834
+ }
4835
+ } ) ;
4836
+ module ( 'owComponentTest' ) ;
4837
+ inject ( function ( ) {
4838
+ $rootScope . name = 'outer' ;
4839
+ compile ( '<ow-component input="name"></ow-component>' ) ;
4840
+ $rootScope . $apply ( ) ;
4841
+
4842
+ expect ( $rootScope . name ) . toEqual ( 'outer' ) ;
4843
+ expect ( component . input ) . toEqual ( '$onInit' ) ;
4844
+ } ) ;
4845
+ } ) ;
4799
4846
4800
4847
it ( 'should not break when isolate and origin both change to the same value' , inject ( function ( ) {
4801
4848
$rootScope . name = 'aaa' ;
@@ -4849,6 +4896,8 @@ describe('$compile', function() {
4849
4896
4850
4897
it ( 'should not throw on non assignable expressions in the parent' , inject ( function ( ) {
4851
4898
compile ( '<div><span my-component ow-ref="\'hello \' + name">' ) ;
4899
+ $rootScope . $apply ( ) ;
4900
+
4852
4901
$rootScope . name = 'world' ;
4853
4902
$rootScope . $apply ( ) ;
4854
4903
expect ( componentScope . owRef ) . toBe ( 'hello world' ) ;
@@ -4879,6 +4928,8 @@ describe('$compile', function() {
4879
4928
it ( 'should update isolate scope when "<"-bound NaN changes' , inject ( function ( ) {
4880
4929
$rootScope . num = NaN ;
4881
4930
compile ( '<div my-component ow-ref="num"></div>' ) ;
4931
+ $rootScope . $apply ( ) ;
4932
+
4882
4933
var isolateScope = element . isolateScope ( ) ;
4883
4934
expect ( isolateScope . owRef ) . toBeNaN ( ) ;
4884
4935
@@ -4891,6 +4942,7 @@ describe('$compile', function() {
4891
4942
describe ( 'literal objects' , function ( ) {
4892
4943
it ( 'should copy parent changes' , inject ( function ( ) {
4893
4944
compile ( '<div><span my-component ow-ref="{name: name}">' ) ;
4945
+ $rootScope . $apply ( ) ;
4894
4946
4895
4947
$rootScope . name = 'a' ;
4896
4948
$rootScope . $apply ( ) ;
@@ -4976,6 +5028,8 @@ describe('$compile', function() {
4976
5028
describe ( 'optional one-way binding' , function ( ) {
4977
5029
it ( 'should update local when origin changes' , inject ( function ( ) {
4978
5030
compile ( '<div><span my-component ow-optref="name">' ) ;
5031
+ $rootScope . $apply ( ) ;
5032
+
4979
5033
expect ( componentScope . owOptref ) . toBeUndefined ( ) ;
4980
5034
expect ( componentScope . owOptrefAlias ) . toBe ( componentScope . owOptref ) ;
4981
5035
0 commit comments