@@ -123,16 +123,12 @@ describe('uiView', function () {
123
123
. state ( 'l' , lState )
124
124
. state ( 'm' , {
125
125
controller : function ( $scope ) {
126
- log += 'm;' ;
127
- $scope . $on ( '$destroy' , function ( ) {
128
- log += '$destroy(m);' ;
129
- } ) ;
130
- } ,
126
+ log += 'ctrl(m);' ;
127
+ $scope . $on ( '$destroy' , function ( ) { log += '$destroy(m);' ; } ) ;
128
+ }
131
129
} )
132
130
. state ( 'n' , {
133
- controller : function ( $scope ) {
134
- log += 'n;' ;
135
- } ,
131
+ controller : function ( $scope ) { log += 'ctrl(n);' ; }
136
132
} ) ;
137
133
} ) ) ;
138
134
@@ -144,23 +140,6 @@ describe('uiView', function () {
144
140
145
141
describe ( 'linking ui-directive' , function ( ) {
146
142
147
- it ( '$destroy event is triggered after animation ends' , inject ( function ( $state , $q , $animate ) {
148
- elem . append ( $compile ( '<div><ui-view></ui-view></div>' ) ( scope ) ) ;
149
-
150
- $state . transitionTo ( 'm' ) ;
151
- $q . flush ( ) ;
152
- expect ( log ) . toBe ( 'm;' ) ;
153
- $state . transitionTo ( 'n' ) ;
154
- $q . flush ( ) ;
155
- if ( $animate ) {
156
- expect ( log ) . toBe ( 'm;n;' ) ;
157
- animateFlush ( $animate ) ;
158
- expect ( log ) . toBe ( 'm;n;$destroy(m);' ) ;
159
- } else {
160
- expect ( log ) . toBe ( 'm;$destroy(m);n;' ) ;
161
- }
162
- } ) ) ;
163
-
164
143
it ( 'anonymous ui-view should be replaced with the template of the current $state' , inject ( function ( $state , $q ) {
165
144
elem . append ( $compile ( '<div><ui-view></ui-view></div>' ) ( scope ) ) ;
166
145
@@ -594,5 +573,56 @@ describe('uiView', function () {
594
573
// No more animations
595
574
expect ( $animate . queue . length ) . toBe ( 0 ) ;
596
575
} ) ) ;
576
+
577
+ it ( 'should disable animations if noanimation="true" is present' , inject ( function ( $state , $q , $compile , $animate ) {
578
+ var content = 'Initial Content' , animation ;
579
+ elem . append ( $compile ( '<div><ui-view noanimation="true">' + content + '</ui-view></div>' ) ( scope ) ) ;
580
+
581
+ animation = $animate . queue . shift ( ) ;
582
+ expect ( animation ) . toBeUndefined ( ) ;
583
+
584
+ $state . transitionTo ( aState ) ;
585
+ $q . flush ( ) ;
586
+ animation = $animate . queue . shift ( ) ;
587
+ expect ( animation ) . toBeUndefined ( ) ;
588
+ expect ( elem . text ( ) ) . toBe ( aState . template ) ;
589
+
590
+ $state . transitionTo ( bState ) ;
591
+ $q . flush ( ) ;
592
+ animation = $animate . queue . shift ( ) ;
593
+ expect ( animation ) . toBeUndefined ( ) ;
594
+ expect ( elem . text ( ) ) . toBe ( bState . template ) ;
595
+ } ) ) ;
596
+
597
+ it ( '$destroy event is triggered after animation ends' , inject ( function ( $state , $q , $animate , $rootScope ) {
598
+ elem . append ( $compile ( '<div><ui-view></ui-view></div>' ) ( scope ) ) ;
599
+ $rootScope . $on ( '$stateChangeSuccess' , function ( evt , toState ) { log += 'success(' + toState . name + ');' ; } ) ;
600
+
601
+ $state . transitionTo ( 'm' ) ;
602
+ $q . flush ( ) ;
603
+ expect ( log ) . toBe ( 'success(m);ctrl(m);' ) ;
604
+ $state . transitionTo ( 'n' ) ;
605
+ $q . flush ( ) ;
606
+ if ( $animate ) {
607
+ expect ( log ) . toBe ( 'success(m);ctrl(m);success(n);ctrl(n);' ) ;
608
+ animateFlush ( $animate ) ;
609
+ expect ( log ) . toBe ( 'success(m);ctrl(m);success(n);ctrl(n);$destroy(m);' ) ;
610
+ } else {
611
+ expect ( log ) . toBe ( 'success(m);ctrl(m);$destroy(m);success(n);ctrl(n);' ) ;
612
+ }
613
+ } ) ) ;
614
+
615
+ it ( '$destroy event is triggered before $stateChangeSuccess if noanimation is present' , inject ( function ( $state , $q , $animate , $rootScope ) {
616
+ elem . append ( $compile ( '<div><ui-view noanimation="true"></ui-view></div>' ) ( scope ) ) ;
617
+ $rootScope . $on ( '$stateChangeSuccess' , function ( evt , toState ) { log += 'success(' + toState . name + ');' ; } ) ;
618
+
619
+ $state . transitionTo ( 'm' ) ;
620
+ $q . flush ( ) ;
621
+ expect ( log ) . toBe ( 'success(m);ctrl(m);' ) ;
622
+ $state . transitionTo ( 'n' ) ;
623
+ $q . flush ( ) ;
624
+ expect ( log ) . toBe ( 'success(m);ctrl(m);success(n);$destroy(m);ctrl(n);' ) ;
625
+ } ) ) ;
626
+
597
627
} ) ;
598
628
} ) ;
0 commit comments