@@ -778,7 +778,11 @@ describe('angular 1.5+ style .component()', function() {
778
778
return {
779
779
scope : { data : '=' } ,
780
780
templateUrl : '/comp_tpl.html' ,
781
- controller : function ( ) { } ,
781
+ controller : function ( ) {
782
+ this . $onInit = function ( ) {
783
+ log += "onInit;"
784
+ }
785
+ } ,
782
786
bindToController : true ,
783
787
controllerAs : '$ctrl'
784
788
}
@@ -832,8 +836,7 @@ describe('angular 1.5+ style .component()', function() {
832
836
$httpBackend . expectGET ( '/state_tpl.html' ) . respond ( 'x<ng12-directive data="$resolve.data"></ng12-directive>x' ) ;
833
837
$httpBackend . expectGET ( '/comp_tpl.html' ) . respond ( '-{{ $ctrl.data }}-' ) ;
834
838
835
- $state . transitionTo ( 'cmp_tpl' ) ;
836
- $q . flush ( ) ;
839
+ $state . transitionTo ( 'cmp_tpl' ) ; $q . flush ( ) ;
837
840
838
841
// Template has not yet been fetched
839
842
var directiveEl = el [ 0 ] . querySelector ( 'div ui-view ng12-directive' ) ;
@@ -857,9 +860,7 @@ describe('angular 1.5+ style .component()', function() {
857
860
$httpBackend . expectGET ( '/state_tpl.html' ) . respond ( 'x<ng13-directive data="$resolve.data"></ng13-directive>x' ) ;
858
861
$httpBackend . expectGET ( '/comp_tpl.html' ) . respond ( '-{{ $ctrl.data }}-' ) ;
859
862
860
- $state . transitionTo ( 'cmp_tpl' ) ;
861
- $q . flush ( ) ;
862
- $httpBackend . flush ( ) ;
863
+ $state . transitionTo ( 'cmp_tpl' ) ; $q . flush ( ) ; $httpBackend . flush ( ) ;
863
864
864
865
directiveEl = el [ 0 ] . querySelector ( 'div ui-view ng13-directive' ) ;
865
866
expect ( directiveEl ) . toBeDefined ( ) ;
@@ -877,9 +878,7 @@ describe('angular 1.5+ style .component()', function() {
877
878
$httpBackend . expectGET ( '/state_tpl.html' ) . respond ( 'x<ng-component data="$resolve.data"></ng-component>x' ) ;
878
879
$httpBackend . expectGET ( '/comp_tpl.html' ) . respond ( '-{{ $ctrl.data }}-' ) ;
879
880
880
- $state . transitionTo ( 'cmp_tpl' ) ;
881
- $q . flush ( ) ;
882
- $httpBackend . flush ( ) ;
881
+ $state . transitionTo ( 'cmp_tpl' ) ; $q . flush ( ) ; $httpBackend . flush ( ) ;
883
882
884
883
directiveEl = el [ 0 ] . querySelector ( 'div ui-view ng-component' ) ;
885
884
expect ( directiveEl ) . toBeDefined ( ) ;
@@ -918,10 +917,8 @@ describe('angular 1.5+ style .component()', function() {
918
917
919
918
var $state = svcs . $state , $httpBackend = svcs . $httpBackend , $q = svcs . $q ;
920
919
921
- $state . transitionTo ( 'route2cmp' ) ;
922
920
$httpBackend . expectGET ( '/comp_tpl.html' ) . respond ( '-{{ $ctrl.data }}-' ) ;
923
- $q . flush ( ) ;
924
- $httpBackend . flush ( ) ;
921
+ $state . transitionTo ( 'route2cmp' ) ; $q . flush ( ) ; $httpBackend . flush ( ) ;
925
922
926
923
directiveEl = el [ 0 ] . querySelector ( 'div ui-view ng12-directive' ) ;
927
924
expect ( directiveEl ) . toBeDefined ( ) ;
@@ -939,16 +936,29 @@ describe('angular 1.5+ style .component()', function() {
939
936
940
937
var $state = svcs . $state , $httpBackend = svcs . $httpBackend , $q = svcs . $q ;
941
938
942
- $state . transitionTo ( 'route2cmp' ) ;
943
939
$httpBackend . expectGET ( '/comp_tpl.html' ) . respond ( '-{{ $ctrl.data }}-' ) ;
944
- $q . flush ( ) ;
945
- $httpBackend . flush ( ) ;
940
+ $state . transitionTo ( 'route2cmp' ) ; $q . flush ( ) ; $httpBackend . flush ( ) ;
946
941
947
942
directiveEl = el [ 0 ] . querySelector ( 'div ui-view ng13-directive' ) ;
948
943
expect ( directiveEl ) . toBeDefined ( ) ;
949
944
expect ( $state . current . name ) . toBe ( 'route2cmp' ) ;
950
945
expect ( el . text ( ) ) . toBe ( '-DATA!-' ) ;
951
946
} ) ;
947
+
948
+ it ( 'should call $onInit() once' , function ( ) {
949
+ $stateProvider . state ( 'route2cmp' , {
950
+ url : '/route2cmp' ,
951
+ component : 'ng13Directive' ,
952
+ resolve : { data : function ( ) { return "DATA!" ; } }
953
+ } ) ;
954
+
955
+ var $state = svcs . $state , $httpBackend = svcs . $httpBackend , $q = svcs . $q ;
956
+
957
+ $httpBackend . expectGET ( '/comp_tpl.html' ) . respond ( '-{{ $ctrl.data }}-' ) ;
958
+ $state . transitionTo ( 'route2cmp' ) ; $q . flush ( ) ; $httpBackend . flush ( ) ;
959
+
960
+ expect ( log ) . toBe ( 'onInit;' ) ;
961
+ } ) ;
952
962
}
953
963
954
964
if ( angular . version . minor >= 5 ) {
@@ -961,16 +971,28 @@ describe('angular 1.5+ style .component()', function() {
961
971
962
972
var $state = svcs . $state , $httpBackend = svcs . $httpBackend , $q = svcs . $q ;
963
973
964
- $state . transitionTo ( 'route2cmp' ) ;
965
974
$httpBackend . expectGET ( '/comp_tpl.html' ) . respond ( '-{{ $ctrl.data }}-' ) ;
966
- $q . flush ( ) ;
967
- $httpBackend . flush ( ) ;
975
+ $state . transitionTo ( 'route2cmp' ) ; $q . flush ( ) ; $httpBackend . flush ( ) ;
968
976
969
977
directiveEl = el [ 0 ] . querySelector ( 'div ui-view ng-component' ) ;
970
978
expect ( directiveEl ) . toBeDefined ( ) ;
971
979
expect ( $state . current . name ) . toBe ( 'route2cmp' ) ;
972
980
expect ( el . text ( ) ) . toBe ( '-DATA!-' ) ;
973
981
} ) ;
982
+
983
+ it ( 'should only call $onInit() once' , function ( ) {
984
+ $stateProvider . state ( 'route2cmp' , {
985
+ component : 'ngComponent' ,
986
+ resolve : { data : function ( ) { return "DATA!" ; } }
987
+ } ) ;
988
+
989
+ var $state = svcs . $state , $httpBackend = svcs . $httpBackend , $q = svcs . $q ;
990
+
991
+ $httpBackend . expectGET ( '/comp_tpl.html' ) . respond ( '-{{ $ctrl.data }}-' ) ;
992
+ $state . transitionTo ( 'route2cmp' ) ; $q . flush ( ) ; $httpBackend . flush ( ) ;
993
+
994
+ expect ( log ) . toBe ( 'onInit;' ) ;
995
+ } ) ;
974
996
}
975
997
} ) ;
976
998
@@ -1007,10 +1029,9 @@ describe('angular 1.5+ style .component()', function() {
1007
1029
$stateProvider . state ( 'route2cmp' , stateDef ) ;
1008
1030
var $state = svcs . $state , $httpBackend = svcs . $httpBackend , $q = svcs . $q ;
1009
1031
1010
- $state . transitionTo ( 'route2cmp' ) ;
1011
1032
$httpBackend . expectGET ( '/comp_tpl.html' ) . respond ( '-{{ $ctrl.data }}-' ) ;
1012
- $q . flush ( ) ;
1013
- $httpBackend . flush ( ) ;
1033
+ $state . transitionTo ( 'route2cmp' ) ; $q . flush ( ) ; $httpBackend . flush ( ) ;
1034
+
1014
1035
var header = el [ 0 ] . querySelector ( '[ui-view=header]' ) ;
1015
1036
var content = el [ 0 ] . querySelector ( '[ui-view=content]' ) ;
1016
1037
@@ -1030,10 +1051,9 @@ describe('angular 1.5+ style .component()', function() {
1030
1051
$stateProvider . state ( 'route2cmp' , stateDef ) ;
1031
1052
var $state = svcs . $state , $httpBackend = svcs . $httpBackend , $q = svcs . $q ;
1032
1053
1033
- $state . transitionTo ( 'route2cmp' ) ;
1034
1054
$httpBackend . expectGET ( '/comp_tpl.html' ) . respond ( '-{{ $ctrl.data }}-' ) ;
1035
- $q . flush ( ) ;
1036
- $httpBackend . flush ( ) ;
1055
+ $state . transitionTo ( 'route2cmp' ) ; $q . flush ( ) ; $httpBackend . flush ( ) ;
1056
+
1037
1057
var header = el [ 0 ] . querySelector ( '[ui-view=header]' ) ;
1038
1058
var content = el [ 0 ] . querySelector ( '[ui-view=content]' ) ;
1039
1059
@@ -1054,10 +1074,8 @@ describe('angular 1.5+ style .component()', function() {
1054
1074
1055
1075
var $state = svcs . $state , $httpBackend = svcs . $httpBackend , $q = svcs . $q ;
1056
1076
1057
- $state . transitionTo ( 'route2cmp' ) ;
1058
1077
$httpBackend . expectGET ( '/comp_tpl.html' ) . respond ( '-{{ $ctrl.data }}-' ) ;
1059
- $q . flush ( ) ;
1060
- $httpBackend . flush ( ) ;
1078
+ $state . transitionTo ( 'route2cmp' ) ; $q . flush ( ) ; $httpBackend . flush ( ) ;
1061
1079
1062
1080
directiveEl = el [ 0 ] . querySelector ( 'div ui-view ng12-directive' ) ;
1063
1081
expect ( directiveEl ) . toBeDefined ( ) ;
@@ -1079,10 +1097,8 @@ describe('angular 1.5+ style .component()', function() {
1079
1097
1080
1098
var $state = svcs . $state , $httpBackend = svcs . $httpBackend , $q = svcs . $q ;
1081
1099
1082
- $state . transitionTo ( 'route2cmp' ) ;
1083
1100
$httpBackend . expectGET ( '/comp_tpl.html' ) . respond ( '-{{ $ctrl.data }}.{{ $ctrl.data2 }}-' ) ;
1084
- $q . flush ( ) ;
1085
- $httpBackend . flush ( ) ;
1101
+ $state . transitionTo ( 'route2cmp' ) ; $q . flush ( ) ; $httpBackend . flush ( ) ;
1086
1102
1087
1103
directiveEl = el [ 0 ] . querySelector ( 'div ui-view ng-component' ) ;
1088
1104
expect ( directiveEl ) . toBeDefined ( ) ;
0 commit comments