@@ -123,6 +123,7 @@ describe('state', function () {
123
123
log = '' ;
124
124
logEvents = logEnterExit = false ;
125
125
$rootScope . $on ( '$stateChangeStart' , eventLogger ) ;
126
+ $rootScope . $on ( '$stateChangeCancel' , eventLogger ) ;
126
127
$rootScope . $on ( '$stateChangeSuccess' , eventLogger ) ;
127
128
$rootScope . $on ( '$stateChangeError' , eventLogger ) ;
128
129
$rootScope . $on ( '$stateNotFound' , eventLogger ) ;
@@ -215,6 +216,25 @@ describe('state', function () {
215
216
expect ( resolvedError ( promise ) ) . toBeTruthy ( ) ;
216
217
} ) ) ;
217
218
219
+ it ( 'can be cancelled by preventDefault() in $stateChangeStart and broadcasts $stateChangeCancel' , inject ( function ( $state , $q , $rootScope ) {
220
+ initStateTo ( A ) ;
221
+ var called , cancelEventCalled ;
222
+ $rootScope . $on ( '$stateChangeStart' , function ( ev ) {
223
+ ev . preventDefault ( ) ;
224
+ called = true ;
225
+ } ) ;
226
+ $rootScope . $on ( '$stateChangeCancel' , function ( ev ) {
227
+ ev . preventDefault ( ) ;
228
+ cancelEventCalled = true ;
229
+ } ) ;
230
+ var promise = $state . transitionTo ( B , { } ) ;
231
+ $q . flush ( ) ;
232
+ expect ( called ) . toBeTruthy ( ) ;
233
+ expect ( cancelEventCalled ) . toBeTruthy ( ) ;
234
+ expect ( $state . current ) . toBe ( A ) ;
235
+ expect ( resolvedError ( promise ) ) . toBeTruthy ( ) ;
236
+ } ) ) ;
237
+
218
238
it ( 'triggers $stateNotFound' , inject ( function ( $state , $q , $rootScope ) {
219
239
initStateTo ( E , { i : 'iii' } ) ;
220
240
var called ;
0 commit comments