@@ -1648,3 +1648,32 @@ describe('$stateParams', function () {
16481648 expect ( $stateParams . foo ) . toBeUndefined ( ) ;
16491649 } ) ) ;
16501650} ) ;
1651+
1652+ // Test for #600, #2238, #2229
1653+ describe ( 'otherwise and state redirects' , function ( ) {
1654+ beforeEach ( module ( function ( $stateProvider , $urlRouterProvider ) {
1655+ $urlRouterProvider . otherwise ( '/home' ) ;
1656+ $stateProvider
1657+ . state ( 'home' , { url : '/home' , template : 'home' } )
1658+ . state ( 'loginPage' , { url : '/login' , templateUrl : 'login.html' } ) ;
1659+ } ) ) ;
1660+
1661+ beforeEach ( inject ( function ( $rootScope , $state ) {
1662+
1663+ $rootScope . $on ( '$stateChangeStart' , function ( event , toState ) {
1664+ if ( toState . name !== "loginPage" ) {
1665+ event . preventDefault ( ) ;
1666+ $state . go ( 'loginPage' , { redirectUrl : toState . name } ) ;
1667+ }
1668+ } ) ;
1669+ } ) ) ;
1670+
1671+ iit ( "should not go into an infinite loop" , inject ( function ( $location , $rootScope , $state , $urlRouter , $httpBackend ) {
1672+ $httpBackend . expectGET ( "login.html" ) . respond ( "login page" ) ;
1673+ $location . url ( "notmatched" ) ;
1674+ $urlRouter . update ( true ) ;
1675+ expect ( function ( ) { $httpBackend . flush ( ) ; } ) . not . toThrow ( ) ;
1676+ expect ( function ( ) { $rootScope . $digest ( ) ; } ) . not . toThrow ( ) ;
1677+ expect ( $state . current . name ) . toBe ( "loginPage" )
1678+ } ) ) ;
1679+ } ) ;
0 commit comments