@@ -3823,6 +3823,7 @@ describe('$compile', function() {
3823
3823
3824
3824
$rootScope . $apply ( 'a = 7' ) ;
3825
3825
element = $compile ( '<c1 prop="a" attr="{{a}}"></c1>' ) ( $rootScope ) ;
3826
+
3826
3827
expect ( log ) . toEqual ( [
3827
3828
{
3828
3829
prop : jasmine . objectContaining ( { currentValue : 7 } ) ,
@@ -3862,6 +3863,7 @@ describe('$compile', function() {
3862
3863
inject ( function ( $compile , $rootScope ) {
3863
3864
$rootScope . $apply ( 'a = 7' ) ;
3864
3865
element = $compile ( '<c1 prop="a" attr="{{a}}"></c1>' ) ( $rootScope ) ;
3866
+
3865
3867
expect ( log ) . toEqual ( [
3866
3868
{
3867
3869
prop : jasmine . objectContaining ( { currentValue : 7 } ) ,
@@ -4744,6 +4746,7 @@ describe('$compile', function() {
4744
4746
describe ( 'one-way binding' , function ( ) {
4745
4747
it ( 'should update isolate when the identity of origin changes' , inject ( function ( ) {
4746
4748
compile ( '<div><span my-component ow-ref="obj">' ) ;
4749
+
4747
4750
expect ( componentScope . owRef ) . toBeUndefined ( ) ;
4748
4751
expect ( componentScope . owRefAlias ) . toBe ( componentScope . owRef ) ;
4749
4752
@@ -4780,6 +4783,7 @@ describe('$compile', function() {
4780
4783
4781
4784
it ( 'should update isolate when both change' , inject ( function ( ) {
4782
4785
compile ( '<div><span my-component ow-ref="name">' ) ;
4786
+
4783
4787
$rootScope . name = { mark :123 } ;
4784
4788
componentScope . owRef = 'misko' ;
4785
4789
@@ -4796,6 +4800,113 @@ describe('$compile', function() {
4796
4800
expect ( componentScope . owRefAlias ) . toBe ( $rootScope . name ) ;
4797
4801
} ) ) ;
4798
4802
4803
+ it ( 'should not update isolate again after $onInit if outer has not changed' , function ( ) {
4804
+ var log = [ ] ;
4805
+ var component ;
4806
+ angular . module ( 'owComponentTest' , [ ] )
4807
+ . component ( 'owComponent' , {
4808
+ bindings : { input : '<' } ,
4809
+ controller : function ( ) {
4810
+ component = this ;
4811
+ this . input = 'constructor' ;
4812
+ log . push ( 'constructor' ) ;
4813
+
4814
+ this . $onInit = function ( ) {
4815
+ this . input = '$onInit' ;
4816
+ log . push ( '$onInit' ) ;
4817
+ } ;
4818
+
4819
+ this . $onChanges = function ( changes ) {
4820
+ if ( changes . input ) {
4821
+ log . push ( [ '$onChanges' , changes . input ] ) ;
4822
+ }
4823
+ } ;
4824
+ }
4825
+ } ) ;
4826
+ module ( 'owComponentTest' ) ;
4827
+ inject ( function ( ) {
4828
+ $rootScope . name = 'outer' ;
4829
+ compile ( '<ow-component input="name"></ow-component>' ) ;
4830
+
4831
+ expect ( $rootScope . name ) . toEqual ( 'outer' ) ;
4832
+ expect ( component . input ) . toEqual ( '$onInit' ) ;
4833
+ expect ( log ) . toEqual ( [
4834
+ 'constructor' ,
4835
+ [ '$onChanges' , jasmine . objectContaining ( { currentValue : 'outer' } ) ] ,
4836
+ '$onInit'
4837
+ ] ) ;
4838
+ } ) ;
4839
+ } ) ;
4840
+
4841
+
4842
+ it ( 'should update isolate again after $onInit if outer has changed (before initial watchAction call)' , function ( ) {
4843
+ var log = [ ] ;
4844
+ var component ;
4845
+ angular . module ( 'owComponentTest' , [ ] )
4846
+ . component ( 'owComponent' , {
4847
+ bindings : { input : '<' } ,
4848
+ controller : function ( ) {
4849
+ component = this ;
4850
+ this . input = 'constructor' ;
4851
+ this . $onInit = function ( ) {
4852
+ this . input = '$onInit' ;
4853
+ } ;
4854
+ this . $onChanges = function ( changes ) {
4855
+ if ( changes . input ) {
4856
+ log . push ( changes . input ) ;
4857
+ }
4858
+ } ;
4859
+ }
4860
+ } ) ;
4861
+ module ( 'owComponentTest' ) ;
4862
+ inject ( function ( ) {
4863
+ $rootScope . name = 'outer1' ;
4864
+ compile ( '<ow-component input="name"></ow-component>' ) ;
4865
+
4866
+ expect ( component . input ) . toEqual ( '$onInit' ) ;
4867
+ $rootScope . $apply ( 'name = "outer2"' ) ;
4868
+
4869
+ expect ( $rootScope . name ) . toEqual ( 'outer2' ) ;
4870
+ expect ( component . input ) . toEqual ( 'outer2' ) ;
4871
+ } ) ;
4872
+ } ) ;
4873
+
4874
+ it ( 'should update isolate again after $onInit if outer has changed (before initial watchAction call)' , function ( ) {
4875
+ var log = [ ] ;
4876
+ var component ;
4877
+ angular . module ( 'owComponentTest' , [ ] )
4878
+ . directive ( 'changeInput' , function ( ) {
4879
+ return function ( scope , elem , attrs ) {
4880
+ scope . name = 'outer2' ;
4881
+ } ;
4882
+ } )
4883
+ . component ( 'owComponent' , {
4884
+ bindings : { input : '<' } ,
4885
+ controller : function ( ) {
4886
+ component = this ;
4887
+ this . input = 'constructor' ;
4888
+ this . $onInit = function ( ) {
4889
+ this . input = '$onInit' ;
4890
+ } ;
4891
+ this . $onChanges = function ( changes ) {
4892
+ if ( changes . input ) {
4893
+ log . push ( changes . input ) ;
4894
+ }
4895
+ } ;
4896
+ }
4897
+ } ) ;
4898
+ module ( 'owComponentTest' ) ;
4899
+ inject ( function ( ) {
4900
+ $rootScope . name = 'outer1' ;
4901
+ compile ( '<ow-component input="name" change-input></ow-component>' ) ;
4902
+
4903
+ expect ( component . input ) . toEqual ( '$onInit' ) ;
4904
+ $rootScope . $digest ( ) ;
4905
+
4906
+ expect ( $rootScope . name ) . toEqual ( 'outer2' ) ;
4907
+ expect ( component . input ) . toEqual ( 'outer2' ) ;
4908
+ } ) ;
4909
+ } ) ;
4799
4910
4800
4911
it ( 'should not break when isolate and origin both change to the same value' , inject ( function ( ) {
4801
4912
$rootScope . name = 'aaa' ;
@@ -4819,7 +4930,6 @@ describe('$compile', function() {
4819
4930
$rootScope . name = { mark :123 } ;
4820
4931
compile ( '<div><span my-component ow-ref="name">' ) ;
4821
4932
4822
- $rootScope . $apply ( ) ;
4823
4933
expect ( $rootScope . name ) . toEqual ( { mark :123 } ) ;
4824
4934
expect ( componentScope . owRef ) . toBe ( $rootScope . name ) ;
4825
4935
expect ( componentScope . owRefAlias ) . toBe ( $rootScope . name ) ;
@@ -4836,7 +4946,6 @@ describe('$compile', function() {
4836
4946
$rootScope . obj = { mark :123 } ;
4837
4947
compile ( '<div><span my-component ow-ref="obj">' ) ;
4838
4948
4839
- $rootScope . $apply ( ) ;
4840
4949
expect ( $rootScope . obj ) . toEqual ( { mark :123 } ) ;
4841
4950
expect ( componentScope . owRef ) . toBe ( $rootScope . obj ) ;
4842
4951
@@ -4849,6 +4958,7 @@ describe('$compile', function() {
4849
4958
4850
4959
it ( 'should not throw on non assignable expressions in the parent' , inject ( function ( ) {
4851
4960
compile ( '<div><span my-component ow-ref="\'hello \' + name">' ) ;
4961
+
4852
4962
$rootScope . name = 'world' ;
4853
4963
$rootScope . $apply ( ) ;
4854
4964
expect ( componentScope . owRef ) . toBe ( 'hello world' ) ;
@@ -4865,7 +4975,7 @@ describe('$compile', function() {
4865
4975
4866
4976
it ( 'should not throw when assigning to undefined' , inject ( function ( ) {
4867
4977
compile ( '<div><span my-component>' ) ;
4868
- $rootScope . $apply ( ) ;
4978
+
4869
4979
expect ( componentScope . owRef ) . toBeUndefined ( ) ;
4870
4980
4871
4981
componentScope . owRef = 'ignore me' ;
@@ -4879,6 +4989,7 @@ describe('$compile', function() {
4879
4989
it ( 'should update isolate scope when "<"-bound NaN changes' , inject ( function ( ) {
4880
4990
$rootScope . num = NaN ;
4881
4991
compile ( '<div my-component ow-ref="num"></div>' ) ;
4992
+
4882
4993
var isolateScope = element . isolateScope ( ) ;
4883
4994
expect ( isolateScope . owRef ) . toBeNaN ( ) ;
4884
4995
@@ -4917,7 +5028,7 @@ describe('$compile', function() {
4917
5028
$rootScope . name = 'georgios' ;
4918
5029
$rootScope . obj = { name : 'pete' } ;
4919
5030
compile ( '<div><span my-component ow-ref="[{name: name}, obj]">' ) ;
4920
- $rootScope . $apply ( ) ;
5031
+
4921
5032
expect ( componentScope . owRef ) . toEqual ( [ { name : 'georgios' } , { name : 'pete' } ] ) ;
4922
5033
4923
5034
$rootScope . name = 'lucas' ;
@@ -4931,7 +5042,7 @@ describe('$compile', function() {
4931
5042
$rootScope . name = 'georgios' ;
4932
5043
$rootScope . obj = { name : 'pete' } ;
4933
5044
compile ( '<div><span my-component ow-ref="{name: name, item: obj}">' ) ;
4934
- $rootScope . $apply ( ) ;
5045
+
4935
5046
expect ( componentScope . owRef ) . toEqual ( { name : 'georgios' , item : { name : 'pete' } } ) ;
4936
5047
4937
5048
$rootScope . name = 'lucas' ;
@@ -4967,7 +5078,6 @@ describe('$compile', function() {
4967
5078
function test ( literalString , literalValue ) {
4968
5079
compile ( '<div><span my-component ow-ref="' + literalString + '">' ) ;
4969
5080
4970
- $rootScope . $apply ( ) ;
4971
5081
expect ( componentScope . owRef ) . toBe ( literalValue ) ;
4972
5082
dealoc ( element ) ;
4973
5083
}
@@ -4976,6 +5086,7 @@ describe('$compile', function() {
4976
5086
describe ( 'optional one-way binding' , function ( ) {
4977
5087
it ( 'should update local when origin changes' , inject ( function ( ) {
4978
5088
compile ( '<div><span my-component ow-optref="name">' ) ;
5089
+
4979
5090
expect ( componentScope . owOptref ) . toBeUndefined ( ) ;
4980
5091
expect ( componentScope . owOptrefAlias ) . toBe ( componentScope . owOptref ) ;
4981
5092
0 commit comments