@@ -37,7 +37,10 @@ describe('state', function () {
37
37
ISS2101 = { params : { bar : { squash : false , value : 'qux' } } , url : '/2101/{bar:string}' } ;
38
38
AppInjectable = { } ;
39
39
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' )
41
44
angular . forEach ( [ A , B , C , D , DD , E , H , HH , HHH ] , function ( state ) {
42
45
state . onEnter = callbackLogger ( 'onEnter' ) ;
43
46
state . onExit = callbackLogger ( 'onExit' ) ;
@@ -1650,6 +1653,35 @@ describe('state queue', function(){
1650
1653
} ) ;
1651
1654
} ) ;
1652
1655
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
+
1653
1685
describe ( '$stateParams' , function ( ) {
1654
1686
beforeEach ( module ( 'ui.router.state' ) ) ;
1655
1687
0 commit comments