Skip to content

Commit ca372ca

Browse files
Merge branch 'metamatt-matt-fail-transition-on-error' into legacy
2 parents d2a0feb + a5756c3 commit ca372ca

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/state.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
11701170
$urlRouter.update(true);
11711171

11721172
return $state.current;
1173-
}, function (error) {
1173+
}).then(null, function (error) {
11741174
if ($state.transition !== transition) return TransitionSuperseded;
11751175

11761176
$state.transition = null;

test/stateSpec.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
16531685
describe('$stateParams', function () {
16541686
beforeEach(module('ui.router.state'));
16551687

0 commit comments

Comments
 (0)