@@ -4,7 +4,7 @@ var uiRouter = require("angular-ui-router");
44describe ( 'uiView' , function ( ) {
55 'use strict' ;
66
7- var scope , $compile , elem ;
7+ var log , scope , $compile , elem ;
88
99 beforeEach ( function ( ) {
1010 var depends = [ 'ui.router' ] ;
@@ -27,6 +27,10 @@ describe('uiView', function () {
2727 } ) ;
2828 } ) ) ;
2929
30+ beforeEach ( function ( ) {
31+ log = '' ;
32+ } ) ;
33+
3034 var aState = {
3135 template : 'aState template'
3236 } ,
@@ -98,8 +102,9 @@ describe('uiView', function () {
98102 }
99103 }
100104 } ,
101- mState = {
102- template : 'mState' ,
105+
106+ oState = {
107+ template : 'oState' ,
103108 controller : function ( $scope , $element ) {
104109 $scope . elementId = $element . attr ( 'id' ) ;
105110 }
@@ -119,7 +124,22 @@ describe('uiView', function () {
119124 . state ( 'j' , jState )
120125 . state ( 'k' , kState )
121126 . 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 )
123143 } ) ) ;
124144
125145 beforeEach ( inject ( function ( $rootScope , _$compile_ ) {
@@ -130,6 +150,23 @@ describe('uiView', function () {
130150
131151 describe ( 'linking ui-directive' , function ( ) {
132152
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+
133170 it ( 'anonymous ui-view should be replaced with the template of the current $state' , inject ( function ( $state , $q ) {
134171 elem . append ( $compile ( '<div><ui-view></ui-view></div>' ) ( scope ) ) ;
135172
@@ -315,11 +352,11 @@ describe('uiView', function () {
315352 } ) ) ;
316353
317354 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 ) ;
320357 $q . flush ( ) ;
321358
322- expect ( elem . text ( ) ) . toBe ( 'mState ' ) ;
359+ expect ( elem . text ( ) ) . toBe ( 'oState ' ) ;
323360 } ) ) ;
324361
325362 describe ( 'play nicely with other directives' , function ( ) {
0 commit comments