@@ -2096,13 +2096,20 @@ describe('otherwise and state redirects', function() {
20962096
20972097
20982098describe ( 'hook redirects from .otherwise()' , function ( ) {
2099+ var log ;
20992100 beforeEach ( module ( function ( $stateProvider , $urlRouterProvider ) {
2101+ log = "" ;
21002102 $urlRouterProvider . otherwise ( '/home' ) ;
21012103 $stateProvider
2102- . state ( 'home' , { url : '/home' , template : 'home' } )
2104+ . state ( 'home' , { url : '/home' , template : 'home' , controller : function ( ) { log += "homeCtrl;" ; } } )
21032105 . state ( 'loginPage' , { url : '/login' , template : 'login' } ) ;
21042106 } ) ) ;
21052107
2108+ beforeEach ( inject ( function ( $compile , $rootScope ) {
2109+ var $scope = $rootScope . $new ( ) ;
2110+ $compile ( '<div><ui-view></ui-view></div>' ) ( $scope ) ;
2111+ } ) ) ;
2112+
21062113 // Test for #2455
21072114 it ( "should go to the redirect-to target state and url" , inject ( function ( $transitions , $q , $state , $location ) {
21082115 $transitions . onBefore ( { to : 'home' } , function ( ) {
@@ -2112,4 +2119,27 @@ describe('hook redirects from .otherwise()', function() {
21122119 expect ( $state . current . name ) . toBe ( "loginPage" ) ;
21132120 expect ( $location . path ( ) ) . toBe ( '/login' ) ;
21142121 } ) ) ;
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+ } ) ) ;
21152145} ) ;
0 commit comments