@@ -14,7 +14,7 @@ function animateFlush($animate) {
14
14
describe ( 'uiView' , function ( ) {
15
15
'use strict' ;
16
16
17
- var log , scope , $compile , elem ;
17
+ var log , scope , $compile , elem , $onInit ;
18
18
19
19
beforeEach ( function ( ) {
20
20
var depends = [ 'ui.router' , 'ui.router.state.events' ] ;
@@ -40,6 +40,7 @@ describe('uiView', function () {
40
40
41
41
beforeEach ( function ( ) {
42
42
log = '' ;
43
+ $onInit = jasmine . createSpy ( '$onInit' ) ;
43
44
} ) ;
44
45
45
46
var aState = {
@@ -119,6 +120,13 @@ describe('uiView', function () {
119
120
controller : function ( $scope , $element ) {
120
121
$scope . elementId = $element . attr ( 'id' ) ;
121
122
}
123
+ } ,
124
+ pState = {
125
+ controller : function ( ) {
126
+ this . $onInit = $onInit ;
127
+ } ,
128
+ template : "hi" ,
129
+ controllerAs : "vm"
122
130
} ;
123
131
124
132
beforeEach ( module ( function ( $stateProvider ) {
@@ -147,6 +155,7 @@ describe('uiView', function () {
147
155
controller : function ( $scope ) { log += 'ctrl(n);' ; }
148
156
} )
149
157
. state ( 'o' , oState )
158
+ . state ( 'p' , pState )
150
159
} ) ) ;
151
160
152
161
beforeEach ( inject ( function ( $rootScope , _$compile_ ) {
@@ -349,6 +358,14 @@ describe('uiView', function () {
349
358
expect ( elem . text ( ) ) . toBe ( 'oState' ) ;
350
359
} ) ) ;
351
360
361
+ it ( 'should call the existing $onInit after instantiating a controller' , inject ( function ( $state , $q ) {
362
+ elem . append ( $compile ( '<div><ui-view></ui-view></div>' ) ( scope ) ) ;
363
+ $state . transitionTo ( pState ) ;
364
+ $q . flush ( ) ;
365
+
366
+ expect ( $onInit ) . toHaveBeenCalled ( ) ;
367
+ } ) ) ;
368
+
352
369
describe ( 'play nicely with other directives' , function ( ) {
353
370
// related to issue #857
354
371
it ( 'should work with ngIf' , inject ( function ( $state , $q , $compile ) {
0 commit comments