@@ -2096,13 +2096,20 @@ describe('otherwise and state redirects', function() {
2096
2096
2097
2097
2098
2098
describe ( 'hook redirects from .otherwise()' , function ( ) {
2099
+ var log ;
2099
2100
beforeEach ( module ( function ( $stateProvider , $urlRouterProvider ) {
2101
+ log = "" ;
2100
2102
$urlRouterProvider . otherwise ( '/home' ) ;
2101
2103
$stateProvider
2102
- . state ( 'home' , { url : '/home' , template : 'home' } )
2104
+ . state ( 'home' , { url : '/home' , template : 'home' , controller : function ( ) { log += "homeCtrl;" ; } } )
2103
2105
. state ( 'loginPage' , { url : '/login' , template : 'login' } ) ;
2104
2106
} ) ) ;
2105
2107
2108
+ beforeEach ( inject ( function ( $compile , $rootScope ) {
2109
+ var $scope = $rootScope . $new ( ) ;
2110
+ $compile ( '<div><ui-view></ui-view></div>' ) ( $scope ) ;
2111
+ } ) ) ;
2112
+
2106
2113
// Test for #2455
2107
2114
it ( "should go to the redirect-to target state and url" , inject ( function ( $transitions , $q , $state , $location ) {
2108
2115
$transitions . onBefore ( { to : 'home' } , function ( ) {
@@ -2112,4 +2119,27 @@ describe('hook redirects from .otherwise()', function() {
2112
2119
expect ( $state . current . name ) . toBe ( "loginPage" ) ;
2113
2120
expect ( $location . path ( ) ) . toBe ( '/login' ) ;
2114
2121
} ) ) ;
2122
+
2123
+ // Test for #2537
2124
+ it ( "should be able to change option.reload" , inject ( function ( $transitions , $q , $state , $trace ) {
2125
+ var count = 0 ;
2126
+ $q . flush ( ) ;
2127
+ expect ( $state . current . name ) . toBe ( "home" ) ;
2128
+ expect ( log ) . toBe ( "homeCtrl;" ) ;
2129
+
2130
+ $state . go ( '.' ) ; $q . flush ( ) ;
2131
+ expect ( log ) . toBe ( "homeCtrl;" ) ;
2132
+
2133
+ $transitions . onBefore ( { to : 'home' } , function ( $state , $transition$ ) {
2134
+ var options = $transition$ . options ( ) ;
2135
+ if ( ! options . reload && count ++ < 2 ) {
2136
+ return $state . target ( $transition$ . to ( ) , $transition$ . params ( "to" ) , extend ( { } , options , { reload : true } ) ) ;
2137
+ }
2138
+ } ) ;
2139
+
2140
+ $state . go ( '.' ) ; $q . flush ( ) ;
2141
+
2142
+ expect ( $state . current . name ) . toBe ( "home" ) ;
2143
+ expect ( log ) . toBe ( "homeCtrl;homeCtrl;" ) ;
2144
+ } ) ) ;
2115
2145
} ) ;
0 commit comments