@@ -4758,7 +4758,6 @@ describe('$compile', function() {
4758
4758
describe ( 'one-way binding' , function ( ) {
4759
4759
it ( 'should update isolate when the identity of origin changes' , inject ( function ( ) {
4760
4760
compile ( '<div><span my-component ow-ref="obj">' ) ;
4761
- $rootScope . $apply ( ) ;
4762
4761
4763
4762
expect ( componentScope . owRef ) . toBeUndefined ( ) ;
4764
4763
expect ( componentScope . owRefAlias ) . toBe ( componentScope . owRef ) ;
@@ -4796,7 +4795,6 @@ describe('$compile', function() {
4796
4795
4797
4796
it ( 'should update isolate when both change' , inject ( function ( ) {
4798
4797
compile ( '<div><span my-component ow-ref="name">' ) ;
4799
- $rootScope . $apply ( ) ;
4800
4798
4801
4799
$rootScope . name = { mark :123 } ;
4802
4800
componentScope . owRef = 'misko' ;
@@ -4841,7 +4839,6 @@ describe('$compile', function() {
4841
4839
inject ( function ( ) {
4842
4840
$rootScope . name = 'outer' ;
4843
4841
compile ( '<ow-component input="name"></ow-component>' ) ;
4844
- $rootScope . $apply ( ) ;
4845
4842
4846
4843
expect ( $rootScope . name ) . toEqual ( 'outer' ) ;
4847
4844
expect ( component . input ) . toEqual ( '$onInit' ) ;
@@ -4853,6 +4850,76 @@ describe('$compile', function() {
4853
4850
} ) ;
4854
4851
} ) ;
4855
4852
4853
+
4854
+ it ( 'should update isolate again after $onInit if outer has changed (before initial watchAction call)' , function ( ) {
4855
+ var log = [ ] ;
4856
+ var component ;
4857
+ angular . module ( 'owComponentTest' , [ ] )
4858
+ . component ( 'owComponent' , {
4859
+ bindings : { input : '<' } ,
4860
+ controller : function ( ) {
4861
+ component = this ;
4862
+ this . input = 'constructor' ;
4863
+ this . $onInit = function ( ) {
4864
+ this . input = '$onInit' ;
4865
+ } ;
4866
+ this . $onChanges = function ( changes ) {
4867
+ if ( changes . input ) {
4868
+ log . push ( changes . input ) ;
4869
+ }
4870
+ } ;
4871
+ }
4872
+ } ) ;
4873
+ module ( 'owComponentTest' ) ;
4874
+ inject ( function ( ) {
4875
+ $rootScope . name = 'outer1' ;
4876
+ compile ( '<ow-component input="name"></ow-component>' ) ;
4877
+
4878
+ expect ( component . input ) . toEqual ( '$onInit' ) ;
4879
+ $rootScope . $apply ( 'name = "outer2"' ) ;
4880
+
4881
+ expect ( $rootScope . name ) . toEqual ( 'outer2' ) ;
4882
+ expect ( component . input ) . toEqual ( 'outer2' ) ;
4883
+ } ) ;
4884
+ } ) ;
4885
+
4886
+ it ( 'should update isolate again after $onInit if outer has changed (before initial watchAction call)' , function ( ) {
4887
+ var log = [ ] ;
4888
+ var component ;
4889
+ angular . module ( 'owComponentTest' , [ ] )
4890
+ . directive ( 'changeInput' , function ( ) {
4891
+ return function ( scope , elem , attrs ) {
4892
+ scope . name = 'outer2' ;
4893
+ } ;
4894
+ } )
4895
+ . component ( 'owComponent' , {
4896
+ bindings : { input : '<' } ,
4897
+ controller : function ( ) {
4898
+ component = this ;
4899
+ this . input = 'constructor' ;
4900
+ this . $onInit = function ( ) {
4901
+ this . input = '$onInit' ;
4902
+ } ;
4903
+ this . $onChanges = function ( changes ) {
4904
+ if ( changes . input ) {
4905
+ log . push ( changes . input ) ;
4906
+ }
4907
+ } ;
4908
+ }
4909
+ } ) ;
4910
+ module ( 'owComponentTest' ) ;
4911
+ inject ( function ( ) {
4912
+ $rootScope . name = 'outer1' ;
4913
+ compile ( '<ow-component input="name" change-input></ow-component>' ) ;
4914
+
4915
+ expect ( component . input ) . toEqual ( '$onInit' ) ;
4916
+ $rootScope . $digest ( ) ;
4917
+
4918
+ expect ( $rootScope . name ) . toEqual ( 'outer2' ) ;
4919
+ expect ( component . input ) . toEqual ( 'outer2' ) ;
4920
+ } ) ;
4921
+ } ) ;
4922
+
4856
4923
it ( 'should not break when isolate and origin both change to the same value' , inject ( function ( ) {
4857
4924
$rootScope . name = 'aaa' ;
4858
4925
compile ( '<div><span my-component ow-ref="name">' ) ;
@@ -4875,7 +4942,6 @@ describe('$compile', function() {
4875
4942
$rootScope . name = { mark :123 } ;
4876
4943
compile ( '<div><span my-component ow-ref="name">' ) ;
4877
4944
4878
- $rootScope . $apply ( ) ;
4879
4945
expect ( $rootScope . name ) . toEqual ( { mark :123 } ) ;
4880
4946
expect ( componentScope . owRef ) . toBe ( $rootScope . name ) ;
4881
4947
expect ( componentScope . owRefAlias ) . toBe ( $rootScope . name ) ;
@@ -4892,7 +4958,6 @@ describe('$compile', function() {
4892
4958
$rootScope . obj = { mark :123 } ;
4893
4959
compile ( '<div><span my-component ow-ref="obj">' ) ;
4894
4960
4895
- $rootScope . $apply ( ) ;
4896
4961
expect ( $rootScope . obj ) . toEqual ( { mark :123 } ) ;
4897
4962
expect ( componentScope . owRef ) . toBe ( $rootScope . obj ) ;
4898
4963
@@ -4905,7 +4970,6 @@ describe('$compile', function() {
4905
4970
4906
4971
it ( 'should not throw on non assignable expressions in the parent' , inject ( function ( ) {
4907
4972
compile ( '<div><span my-component ow-ref="\'hello \' + name">' ) ;
4908
- $rootScope . $apply ( ) ;
4909
4973
4910
4974
$rootScope . name = 'world' ;
4911
4975
$rootScope . $apply ( ) ;
@@ -4923,7 +4987,7 @@ describe('$compile', function() {
4923
4987
4924
4988
it ( 'should not throw when assigning to undefined' , inject ( function ( ) {
4925
4989
compile ( '<div><span my-component>' ) ;
4926
- $rootScope . $apply ( ) ;
4990
+
4927
4991
expect ( componentScope . owRef ) . toBeUndefined ( ) ;
4928
4992
4929
4993
componentScope . owRef = 'ignore me' ;
@@ -4937,7 +5001,6 @@ describe('$compile', function() {
4937
5001
it ( 'should update isolate scope when "<"-bound NaN changes' , inject ( function ( ) {
4938
5002
$rootScope . num = NaN ;
4939
5003
compile ( '<div my-component ow-ref="num"></div>' ) ;
4940
- $rootScope . $apply ( ) ;
4941
5004
4942
5005
var isolateScope = element . isolateScope ( ) ;
4943
5006
expect ( isolateScope . owRef ) . toBeNaN ( ) ;
@@ -4951,7 +5014,6 @@ describe('$compile', function() {
4951
5014
describe ( 'literal objects' , function ( ) {
4952
5015
it ( 'should copy parent changes' , inject ( function ( ) {
4953
5016
compile ( '<div><span my-component ow-ref="{name: name}">' ) ;
4954
- $rootScope . $apply ( ) ;
4955
5017
4956
5018
$rootScope . name = 'a' ;
4957
5019
$rootScope . $apply ( ) ;
@@ -4978,7 +5040,7 @@ describe('$compile', function() {
4978
5040
$rootScope . name = 'georgios' ;
4979
5041
$rootScope . obj = { name : 'pete' } ;
4980
5042
compile ( '<div><span my-component ow-ref="[{name: name}, obj]">' ) ;
4981
- $rootScope . $apply ( ) ;
5043
+
4982
5044
expect ( componentScope . owRef ) . toEqual ( [ { name : 'georgios' } , { name : 'pete' } ] ) ;
4983
5045
4984
5046
$rootScope . name = 'lucas' ;
@@ -4992,7 +5054,7 @@ describe('$compile', function() {
4992
5054
$rootScope . name = 'georgios' ;
4993
5055
$rootScope . obj = { name : 'pete' } ;
4994
5056
compile ( '<div><span my-component ow-ref="{name: name, item: obj}">' ) ;
4995
- $rootScope . $apply ( ) ;
5057
+
4996
5058
expect ( componentScope . owRef ) . toEqual ( { name : 'georgios' , item : { name : 'pete' } } ) ;
4997
5059
4998
5060
$rootScope . name = 'lucas' ;
@@ -5028,7 +5090,6 @@ describe('$compile', function() {
5028
5090
function test ( literalString , literalValue ) {
5029
5091
compile ( '<div><span my-component ow-ref="' + literalString + '">' ) ;
5030
5092
5031
- $rootScope . $apply ( ) ;
5032
5093
expect ( componentScope . owRef ) . toBe ( literalValue ) ;
5033
5094
dealoc ( element ) ;
5034
5095
}
@@ -5037,7 +5098,6 @@ describe('$compile', function() {
5037
5098
describe ( 'optional one-way binding' , function ( ) {
5038
5099
it ( 'should update local when origin changes' , inject ( function ( ) {
5039
5100
compile ( '<div><span my-component ow-optref="name">' ) ;
5040
- $rootScope . $apply ( ) ;
5041
5101
5042
5102
expect ( componentScope . owOptref ) . toBeUndefined ( ) ;
5043
5103
expect ( componentScope . owOptrefAlias ) . toBe ( componentScope . owOptref ) ;
0 commit comments