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