@@ -3822,6 +3822,7 @@ describe('$compile', function() {
3822
3822
3823
3823
$rootScope . $apply ( 'a = 7' ) ;
3824
3824
element = $compile ( '<c1 prop="a" attr="{{a}}"></c1>' ) ( $rootScope ) ;
3825
+
3825
3826
expect ( log ) . toEqual ( [
3826
3827
{
3827
3828
prop : jasmine . objectContaining ( { currentValue : 7 } ) ,
@@ -3861,6 +3862,7 @@ describe('$compile', function() {
3861
3862
inject ( function ( $compile , $rootScope ) {
3862
3863
$rootScope . $apply ( 'a = 7' ) ;
3863
3864
element = $compile ( '<c1 prop="a" attr="{{a}}"></c1>' ) ( $rootScope ) ;
3865
+
3864
3866
expect ( log ) . toEqual ( [
3865
3867
{
3866
3868
prop : jasmine . objectContaining ( { currentValue : 7 } ) ,
@@ -4743,6 +4745,7 @@ describe('$compile', function() {
4743
4745
describe ( 'one-way binding' , function ( ) {
4744
4746
it ( 'should update isolate when the identity of origin changes' , inject ( function ( ) {
4745
4747
compile ( '<div><span my-component ow-ref="obj">' ) ;
4748
+
4746
4749
expect ( componentScope . owRef ) . toBeUndefined ( ) ;
4747
4750
expect ( componentScope . owRefAlias ) . toBe ( componentScope . owRef ) ;
4748
4751
@@ -4779,6 +4782,7 @@ describe('$compile', function() {
4779
4782
4780
4783
it ( 'should update isolate when both change' , inject ( function ( ) {
4781
4784
compile ( '<div><span my-component ow-ref="name">' ) ;
4785
+
4782
4786
$rootScope . name = { mark :123 } ;
4783
4787
componentScope . owRef = 'misko' ;
4784
4788
@@ -4795,6 +4799,101 @@ describe('$compile', function() {
4795
4799
expect ( componentScope . owRefAlias ) . toBe ( $rootScope . name ) ;
4796
4800
} ) ) ;
4797
4801
4802
+ describe ( 'initialization' , function ( ) {
4803
+ var component , log ;
4804
+
4805
+ beforeEach ( function ( ) {
4806
+ log = [ ] ;
4807
+ angular . module ( 'owComponentTest' , [ ] )
4808
+ . component ( 'owComponent' , {
4809
+ bindings : { input : '<' } ,
4810
+ controller : function ( ) {
4811
+ component = this ;
4812
+ this . input = 'constructor' ;
4813
+ log . push ( 'constructor' ) ;
4814
+
4815
+ this . $onInit = function ( ) {
4816
+ this . input = '$onInit' ;
4817
+ log . push ( '$onInit' ) ;
4818
+ } ;
4819
+
4820
+ this . $onChanges = function ( changes ) {
4821
+ if ( changes . input ) {
4822
+ log . push ( [ '$onChanges' , changes . input ] ) ;
4823
+ }
4824
+ } ;
4825
+ }
4826
+ } ) ;
4827
+ } ) ;
4828
+
4829
+ it ( 'should not update isolate again after $onInit if outer has not changed' , function ( ) {
4830
+ module ( 'owComponentTest' ) ;
4831
+ inject ( function ( ) {
4832
+ $rootScope . name = 'outer' ;
4833
+ compile ( '<ow-component input="name"></ow-component>' ) ;
4834
+
4835
+ expect ( $rootScope . name ) . toEqual ( 'outer' ) ;
4836
+ expect ( component . input ) . toEqual ( '$onInit' ) ;
4837
+
4838
+ $rootScope . $apply ( ) ;
4839
+
4840
+ expect ( $rootScope . name ) . toEqual ( 'outer' ) ;
4841
+ expect ( component . input ) . toEqual ( '$onInit' ) ;
4842
+
4843
+ expect ( log ) . toEqual ( [
4844
+ 'constructor' ,
4845
+ [ '$onChanges' , jasmine . objectContaining ( { currentValue : 'outer' } ) ] ,
4846
+ '$onInit'
4847
+ ] ) ;
4848
+ } ) ;
4849
+ } ) ;
4850
+
4851
+ it ( 'should update isolate again after $onInit if outer has changed (before initial watchAction call)' , function ( ) {
4852
+ module ( 'owComponentTest' ) ;
4853
+ inject ( function ( ) {
4854
+ $rootScope . name = 'outer1' ;
4855
+ compile ( '<ow-component input="name"></ow-component>' ) ;
4856
+
4857
+ expect ( component . input ) . toEqual ( '$onInit' ) ;
4858
+ $rootScope . $apply ( 'name = "outer2"' ) ;
4859
+
4860
+ expect ( $rootScope . name ) . toEqual ( 'outer2' ) ;
4861
+ expect ( component . input ) . toEqual ( 'outer2' ) ;
4862
+ expect ( log ) . toEqual ( [
4863
+ 'constructor' ,
4864
+ [ '$onChanges' , jasmine . objectContaining ( { currentValue : 'outer1' } ) ] ,
4865
+ '$onInit' ,
4866
+ [ '$onChanges' , jasmine . objectContaining ( { currentValue : 'outer2' , previousValue : 'outer1' } ) ]
4867
+ ] ) ;
4868
+ } ) ;
4869
+ } ) ;
4870
+
4871
+ it ( 'should update isolate again after $onInit if outer has changed (before initial watchAction call)' , function ( ) {
4872
+ angular . module ( 'owComponentTest' )
4873
+ . directive ( 'changeInput' , function ( ) {
4874
+ return function ( scope , elem , attrs ) {
4875
+ scope . name = 'outer2' ;
4876
+ } ;
4877
+ } ) ;
4878
+ module ( 'owComponentTest' ) ;
4879
+ inject ( function ( ) {
4880
+ $rootScope . name = 'outer1' ;
4881
+ compile ( '<ow-component input="name" change-input></ow-component>' ) ;
4882
+
4883
+ expect ( component . input ) . toEqual ( '$onInit' ) ;
4884
+ $rootScope . $digest ( ) ;
4885
+
4886
+ expect ( $rootScope . name ) . toEqual ( 'outer2' ) ;
4887
+ expect ( component . input ) . toEqual ( 'outer2' ) ;
4888
+ expect ( log ) . toEqual ( [
4889
+ 'constructor' ,
4890
+ [ '$onChanges' , jasmine . objectContaining ( { currentValue : 'outer1' } ) ] ,
4891
+ '$onInit' ,
4892
+ [ '$onChanges' , jasmine . objectContaining ( { currentValue : 'outer2' , previousValue : 'outer1' } ) ]
4893
+ ] ) ;
4894
+ } ) ;
4895
+ } ) ;
4896
+ } ) ;
4798
4897
4799
4898
it ( 'should not break when isolate and origin both change to the same value' , inject ( function ( ) {
4800
4899
$rootScope . name = 'aaa' ;
@@ -4818,7 +4917,6 @@ describe('$compile', function() {
4818
4917
$rootScope . name = { mark :123 } ;
4819
4918
compile ( '<div><span my-component ow-ref="name">' ) ;
4820
4919
4821
- $rootScope . $apply ( ) ;
4822
4920
expect ( $rootScope . name ) . toEqual ( { mark :123 } ) ;
4823
4921
expect ( componentScope . owRef ) . toBe ( $rootScope . name ) ;
4824
4922
expect ( componentScope . owRefAlias ) . toBe ( $rootScope . name ) ;
@@ -4835,7 +4933,6 @@ describe('$compile', function() {
4835
4933
$rootScope . obj = { mark :123 } ;
4836
4934
compile ( '<div><span my-component ow-ref="obj">' ) ;
4837
4935
4838
- $rootScope . $apply ( ) ;
4839
4936
expect ( $rootScope . obj ) . toEqual ( { mark :123 } ) ;
4840
4937
expect ( componentScope . owRef ) . toBe ( $rootScope . obj ) ;
4841
4938
@@ -4848,6 +4945,7 @@ describe('$compile', function() {
4848
4945
4849
4946
it ( 'should not throw on non assignable expressions in the parent' , inject ( function ( ) {
4850
4947
compile ( '<div><span my-component ow-ref="\'hello \' + name">' ) ;
4948
+
4851
4949
$rootScope . name = 'world' ;
4852
4950
$rootScope . $apply ( ) ;
4853
4951
expect ( componentScope . owRef ) . toBe ( 'hello world' ) ;
@@ -4864,7 +4962,7 @@ describe('$compile', function() {
4864
4962
4865
4963
it ( 'should not throw when assigning to undefined' , inject ( function ( ) {
4866
4964
compile ( '<div><span my-component>' ) ;
4867
- $rootScope . $apply ( ) ;
4965
+
4868
4966
expect ( componentScope . owRef ) . toBeUndefined ( ) ;
4869
4967
4870
4968
componentScope . owRef = 'ignore me' ;
@@ -4878,6 +4976,7 @@ describe('$compile', function() {
4878
4976
it ( 'should update isolate scope when "<"-bound NaN changes' , inject ( function ( ) {
4879
4977
$rootScope . num = NaN ;
4880
4978
compile ( '<div my-component ow-ref="num"></div>' ) ;
4979
+
4881
4980
var isolateScope = element . isolateScope ( ) ;
4882
4981
expect ( isolateScope . owRef ) . toBeNaN ( ) ;
4883
4982
@@ -4916,7 +5015,7 @@ describe('$compile', function() {
4916
5015
$rootScope . name = 'georgios' ;
4917
5016
$rootScope . obj = { name : 'pete' } ;
4918
5017
compile ( '<div><span my-component ow-ref="[{name: name}, obj]">' ) ;
4919
- $rootScope . $apply ( ) ;
5018
+
4920
5019
expect ( componentScope . owRef ) . toEqual ( [ { name : 'georgios' } , { name : 'pete' } ] ) ;
4921
5020
4922
5021
$rootScope . name = 'lucas' ;
@@ -4930,7 +5029,7 @@ describe('$compile', function() {
4930
5029
$rootScope . name = 'georgios' ;
4931
5030
$rootScope . obj = { name : 'pete' } ;
4932
5031
compile ( '<div><span my-component ow-ref="{name: name, item: obj}">' ) ;
4933
- $rootScope . $apply ( ) ;
5032
+
4934
5033
expect ( componentScope . owRef ) . toEqual ( { name : 'georgios' , item : { name : 'pete' } } ) ;
4935
5034
4936
5035
$rootScope . name = 'lucas' ;
@@ -4966,7 +5065,6 @@ describe('$compile', function() {
4966
5065
function test ( literalString , literalValue ) {
4967
5066
compile ( '<div><span my-component ow-ref="' + literalString + '">' ) ;
4968
5067
4969
- $rootScope . $apply ( ) ;
4970
5068
expect ( componentScope . owRef ) . toBe ( literalValue ) ;
4971
5069
dealoc ( element ) ;
4972
5070
}
@@ -4975,6 +5073,7 @@ describe('$compile', function() {
4975
5073
describe ( 'optional one-way binding' , function ( ) {
4976
5074
it ( 'should update local when origin changes' , inject ( function ( ) {
4977
5075
compile ( '<div><span my-component ow-optref="name">' ) ;
5076
+
4978
5077
expect ( componentScope . owOptref ) . toBeUndefined ( ) ;
4979
5078
expect ( componentScope . owOptrefAlias ) . toBe ( componentScope . owOptref ) ;
4980
5079
0 commit comments