@@ -123,6 +123,7 @@ describe('state', function () {
123123 log = '' ;
124124 logEvents = logEnterExit = false ;
125125 $rootScope . $on ( '$stateChangeStart' , eventLogger ) ;
126+ $rootScope . $on ( '$stateChangeCancel' , eventLogger ) ;
126127 $rootScope . $on ( '$stateChangeSuccess' , eventLogger ) ;
127128 $rootScope . $on ( '$stateChangeError' , eventLogger ) ;
128129 $rootScope . $on ( '$stateNotFound' , eventLogger ) ;
@@ -215,6 +216,25 @@ describe('state', function () {
215216 expect ( resolvedError ( promise ) ) . toBeTruthy ( ) ;
216217 } ) ) ;
217218
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+
218238 it ( 'triggers $stateNotFound' , inject ( function ( $state , $q , $rootScope ) {
219239 initStateTo ( E , { i : 'iii' } ) ;
220240 var called ;
0 commit comments