@@ -37,7 +37,10 @@ describe('state', function () {
3737 ISS2101 = { params : { bar : { squash : false , value : 'qux' } } , url : '/2101/{bar:string}' } ;
3838 AppInjectable = { } ;
3939
40- beforeEach ( module ( function ( $stateProvider , $provide ) {
40+ beforeEach ( module ( function ( $stateProvider , $provide , $exceptionHandlerProvider ) {
41+ var x = this ;
42+ var foo = jasmine ;
43+ $exceptionHandlerProvider . mode ( 'log' )
4144 angular . forEach ( [ A , B , C , D , DD , E , H , HH , HHH ] , function ( state ) {
4245 state . onEnter = callbackLogger ( 'onEnter' ) ;
4346 state . onExit = callbackLogger ( 'onExit' ) ;
@@ -1650,6 +1653,35 @@ describe('state queue', function(){
16501653 } ) ;
16511654} ) ;
16521655
1656+ describe ( 'exceptions in onEnter' , function ( ) {
1657+ beforeEach ( module ( function ( $stateProvider , $exceptionHandlerProvider ) {
1658+ $exceptionHandlerProvider . mode ( 'log' ) ;
1659+ $stateProvider
1660+ . state ( 'A' , { } )
1661+ . state ( 'onEnterFail' , {
1662+ onEnter : function ( ) {
1663+ throw new Error ( 'negative onEnter' ) ;
1664+ }
1665+ } ) ;
1666+ } ) ) ;
1667+
1668+ it ( 'sends $stateChangeError for exceptions in onEnter' , inject ( function ( $state , $q , $rootScope ) {
1669+ var called ;
1670+ $rootScope . $on ( '$stateChangeError' , function ( ev , to , toParams , from , fromParams , options ) {
1671+ called = true ;
1672+ } ) ;
1673+
1674+ $state . go ( 'A' ) ; $q . flush ( ) ;
1675+ expect ( $state . current . name ) . toEqual ( 'A' ) ;
1676+
1677+ $state . transitionTo ( 'onEnterFail' ) ;
1678+ $q . flush ( ) ;
1679+
1680+ expect ( called ) . toBeTruthy ( ) ;
1681+ expect ( $state . current . name ) . toEqual ( 'A' ) ;
1682+ } ) )
1683+ } ) ;
1684+
16531685describe ( '$stateParams' , function ( ) {
16541686 beforeEach ( module ( 'ui.router.state' ) ) ;
16551687
0 commit comments