@@ -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,96 @@ 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
+ expect(log).toEqual([
4839
+ 'constructor',
4840
+ ['$onChanges', jasmine.objectContaining({ currentValue: 'outer' })],
4841
+ '$onInit'
4842
+ ]);
4843
+ });
4844
+ });
4845
+
4846
+
4847
+ it('should update isolate again after $onInit if outer has changed (before initial watchAction call)', function() {
4848
+ module('owComponentTest');
4849
+ inject(function() {
4850
+ $rootScope.name = 'outer1';
4851
+ compile('<ow-component input="name"></ow-component>');
4852
+
4853
+ expect(component.input).toEqual('$onInit');
4854
+ $rootScope.$apply('name = "outer2"');
4855
+
4856
+ expect($rootScope.name).toEqual('outer2');
4857
+ expect(component.input).toEqual('outer2');
4858
+ expect(log).toEqual([
4859
+ 'constructor',
4860
+ ['$onChanges', jasmine.objectContaining({ currentValue: 'outer1' })],
4861
+ '$onInit',
4862
+ ['$onChanges', jasmine.objectContaining({ currentValue: 'outer2', previousValue: 'outer1' })]
4863
+ ]);
4864
+ });
4865
+ });
4866
+
4867
+ it('should update isolate again after $onInit if outer has changed (before initial watchAction call)', function() {
4868
+ angular.module('owComponentTest')
4869
+ .directive('changeInput', function() {
4870
+ return function(scope, elem, attrs) {
4871
+ scope.name = 'outer2';
4872
+ };
4873
+ });
4874
+ module('owComponentTest');
4875
+ inject(function() {
4876
+ $rootScope.name = 'outer1';
4877
+ compile('<ow-component input="name" change-input></ow-component>');
4878
+
4879
+ expect(component.input).toEqual('$onInit');
4880
+ $rootScope.$digest();
4881
+
4882
+ expect($rootScope.name).toEqual('outer2');
4883
+ expect(component.input).toEqual('outer2');
4884
+ expect(log).toEqual([
4885
+ 'constructor',
4886
+ ['$onChanges', jasmine.objectContaining({ currentValue: 'outer1' })],
4887
+ '$onInit',
4888
+ ['$onChanges', jasmine.objectContaining({ currentValue: 'outer2', previousValue: 'outer1' })]
4889
+ ]);
4890
+ });
4891
+ });
4892
+ });
4799
4893
4800
4894
it('should not break when isolate and origin both change to the same value', inject(function() {
4801
4895
$rootScope.name = 'aaa';
@@ -4819,7 +4913,6 @@ describe('$compile', function() {
4819
4913
$rootScope.name = {mark:123};
4820
4914
compile('<div><span my-component ow-ref="name">');
4821
4915
4822
- $rootScope.$apply();
4823
4916
expect($rootScope.name).toEqual({mark:123});
4824
4917
expect(componentScope.owRef).toBe($rootScope.name);
4825
4918
expect(componentScope.owRefAlias).toBe($rootScope.name);
@@ -4836,7 +4929,6 @@ describe('$compile', function() {
4836
4929
$rootScope.obj = {mark:123};
4837
4930
compile('<div><span my-component ow-ref="obj">');
4838
4931
4839
- $rootScope.$apply();
4840
4932
expect($rootScope.obj).toEqual({mark:123});
4841
4933
expect(componentScope.owRef).toBe($rootScope.obj);
4842
4934
@@ -4849,6 +4941,7 @@ describe('$compile', function() {
4849
4941
4850
4942
it('should not throw on non assignable expressions in the parent', inject(function() {
4851
4943
compile('<div><span my-component ow-ref="\'hello \' + name">');
4944
+
4852
4945
$rootScope.name = 'world';
4853
4946
$rootScope.$apply();
4854
4947
expect(componentScope.owRef).toBe('hello world');
@@ -4865,7 +4958,7 @@ describe('$compile', function() {
4865
4958
4866
4959
it('should not throw when assigning to undefined', inject(function() {
4867
4960
compile('<div><span my-component>');
4868
- $rootScope.$apply();
4961
+
4869
4962
expect(componentScope.owRef).toBeUndefined();
4870
4963
4871
4964
componentScope.owRef = 'ignore me';
@@ -4879,6 +4972,7 @@ describe('$compile', function() {
4879
4972
it('should update isolate scope when "<"-bound NaN changes', inject(function() {
4880
4973
$rootScope.num = NaN;
4881
4974
compile('<div my-component ow-ref="num"></div>');
4975
+
4882
4976
var isolateScope = element.isolateScope();
4883
4977
expect(isolateScope.owRef).toBeNaN();
4884
4978
@@ -4917,7 +5011,7 @@ describe('$compile', function() {
4917
5011
$rootScope.name = 'georgios';
4918
5012
$rootScope.obj = {name: 'pete'};
4919
5013
compile('<div><span my-component ow-ref="[{name: name}, obj]">');
4920
- $rootScope.$apply();
5014
+
4921
5015
expect(componentScope.owRef).toEqual([{name: 'georgios'}, {name: 'pete'}]);
4922
5016
4923
5017
$rootScope.name = 'lucas';
@@ -4931,7 +5025,7 @@ describe('$compile', function() {
4931
5025
$rootScope.name = 'georgios';
4932
5026
$rootScope.obj = {name: 'pete'};
4933
5027
compile('<div><span my-component ow-ref="{name: name, item: obj}">');
4934
- $rootScope.$apply();
5028
+
4935
5029
expect(componentScope.owRef).toEqual({name: 'georgios', item: {name: 'pete'}});
4936
5030
4937
5031
$rootScope.name = 'lucas';
@@ -4967,7 +5061,6 @@ describe('$compile', function() {
4967
5061
function test(literalString, literalValue) {
4968
5062
compile('<div><span my-component ow-ref="' + literalString + '">');
4969
5063
4970
- $rootScope.$apply();
4971
5064
expect(componentScope.owRef).toBe(literalValue);
4972
5065
dealoc(element);
4973
5066
}
@@ -4976,6 +5069,7 @@ describe('$compile', function() {
4976
5069
describe('optional one-way binding', function() {
4977
5070
it('should update local when origin changes', inject(function() {
4978
5071
compile('<div><span my-component ow-optref="name">');
5072
+
4979
5073
expect(componentScope.owOptref).toBeUndefined();
4980
5074
expect(componentScope.owOptrefAlias).toBe(componentScope.owOptref);
4981
5075
0 commit comments