@@ -4,7 +4,7 @@ var uiRouter = require("angular-ui-router");
4
4
describe ( 'uiView' , function ( ) {
5
5
'use strict' ;
6
6
7
- var scope , $compile , elem ;
7
+ var log , scope , $compile , elem ;
8
8
9
9
beforeEach ( function ( ) {
10
10
var depends = [ 'ui.router' ] ;
@@ -27,6 +27,10 @@ describe('uiView', function () {
27
27
} ) ;
28
28
} ) ) ;
29
29
30
+ beforeEach ( function ( ) {
31
+ log = '' ;
32
+ } ) ;
33
+
30
34
var aState = {
31
35
template : 'aState template'
32
36
} ,
@@ -98,8 +102,9 @@ describe('uiView', function () {
98
102
}
99
103
}
100
104
} ,
101
- mState = {
102
- template : 'mState' ,
105
+
106
+ oState = {
107
+ template : 'oState' ,
103
108
controller : function ( $scope , $element ) {
104
109
$scope . elementId = $element . attr ( 'id' ) ;
105
110
}
@@ -119,7 +124,22 @@ describe('uiView', function () {
119
124
. state ( 'j' , jState )
120
125
. state ( 'k' , kState )
121
126
. state ( 'l' , lState )
122
- . state ( 'm' , mState )
127
+ . state ( 'm' , {
128
+ template : 'mState' ,
129
+ controller : function ( $scope ) {
130
+ log += 'm;' ;
131
+ $scope . $on ( '$destroy' , function ( ) {
132
+ log += '$destroy(m);' ;
133
+ } ) ;
134
+ } ,
135
+ } )
136
+ . state ( 'n' , {
137
+ template : 'nState' ,
138
+ controller : function ( $scope ) {
139
+ log += 'n;' ;
140
+ } ,
141
+ } )
142
+ . state ( 'o' , oState )
123
143
} ) ) ;
124
144
125
145
beforeEach ( inject ( function ( $rootScope , _$compile_ ) {
@@ -130,6 +150,23 @@ describe('uiView', function () {
130
150
131
151
describe ( 'linking ui-directive' , function ( ) {
132
152
153
+ it ( '$destroy event is triggered after animation ends' , inject ( function ( $state , $q , $animate ) {
154
+ elem . append ( $compile ( '<div><ui-view></ui-view></div>' ) ( scope ) ) ;
155
+
156
+ $state . transitionTo ( 'm' ) ;
157
+ $q . flush ( ) ;
158
+ expect ( log ) . toBe ( 'm;' ) ;
159
+ $state . transitionTo ( 'n' ) ;
160
+ $q . flush ( ) ;
161
+ if ( $animate ) {
162
+ expect ( log ) . toBe ( 'm;n;' ) ;
163
+ $animate . triggerCallbacks ( ) ;
164
+ expect ( log ) . toBe ( 'm;n;$destroy(m);' ) ;
165
+ } else {
166
+ expect ( log ) . toBe ( 'm;$destroy(m);n;' ) ;
167
+ }
168
+ } ) ) ;
169
+
133
170
it ( 'anonymous ui-view should be replaced with the template of the current $state' , inject ( function ( $state , $q ) {
134
171
elem . append ( $compile ( '<div><ui-view></ui-view></div>' ) ( scope ) ) ;
135
172
@@ -315,11 +352,11 @@ describe('uiView', function () {
315
352
} ) ) ;
316
353
317
354
it ( 'should instantiate a controller with both $scope and $element injections' , inject ( function ( $state , $q ) {
318
- elem . append ( $compile ( '<div><ui-view id="mState ">{{elementId}}</ui-view></div>' ) ( scope ) ) ;
319
- $state . transitionTo ( mState ) ;
355
+ elem . append ( $compile ( '<div><ui-view id="oState ">{{elementId}}</ui-view></div>' ) ( scope ) ) ;
356
+ $state . transitionTo ( oState ) ;
320
357
$q . flush ( ) ;
321
358
322
- expect ( elem . text ( ) ) . toBe ( 'mState ' ) ;
359
+ expect ( elem . text ( ) ) . toBe ( 'oState ' ) ;
323
360
} ) ) ;
324
361
325
362
describe ( 'play nicely with other directives' , function ( ) {
0 commit comments