@@ -141,7 +141,7 @@ describe('uiStateRef', function() {
141
141
ctrlKey : undefined ,
142
142
shiftKey : undefined ,
143
143
altKey : undefined ,
144
- button : undefined
144
+ button : undefined
145
145
} ) ;
146
146
timeoutFlush ( ) ;
147
147
$q . flush ( ) ;
@@ -156,7 +156,7 @@ describe('uiStateRef', function() {
156
156
157
157
timeoutFlush ( ) ;
158
158
$q . flush ( ) ;
159
-
159
+
160
160
expect ( $state . current . name ) . toEqual ( 'top' ) ;
161
161
expect ( $stateParams ) . toEqualData ( { } ) ;
162
162
} ) ) ;
@@ -222,7 +222,7 @@ describe('uiStateRef', function() {
222
222
223
223
it ( 'should allow passing params to current state' , inject ( function ( $compile , $rootScope , $state ) {
224
224
$state . current . name = 'contacts.item.detail' ;
225
-
225
+
226
226
el = angular . element ( "<a ui-sref=\"{id: $index}\">Details</a>" ) ;
227
227
$rootScope . $index = 3 ;
228
228
$rootScope . $apply ( ) ;
@@ -231,10 +231,10 @@ describe('uiStateRef', function() {
231
231
$rootScope . $digest ( ) ;
232
232
expect ( el . attr ( 'href' ) ) . toBe ( '#/contacts/3' ) ;
233
233
} ) ) ;
234
-
234
+
235
235
it ( 'should allow multi-line attribute values when passing params to current state' , inject ( function ( $compile , $rootScope , $state ) {
236
236
$state . current . name = 'contacts.item.detail' ;
237
-
237
+
238
238
el = angular . element ( "<a ui-sref=\"{\n\tid: $index\n}\">Details</a>" ) ;
239
239
$rootScope . $index = 3 ;
240
240
$rootScope . $apply ( ) ;
@@ -257,6 +257,25 @@ describe('uiStateRef', function() {
257
257
$rootScope . $digest ( ) ;
258
258
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'href' ) ) . toBe ( '#/contacts/2' ) ;
259
259
} ) ) ;
260
+
261
+ it ( 'emits $stateChangeCancel when transition rejects' , inject ( function ( $rootScope , $timeout , $state , $q ) {
262
+ var TransitionSupersededError = new Error ( 'Transition superseded' ) ;
263
+
264
+ $rootScope . $on ( '$stateChangeCancel' , function ( _ , e ) {
265
+ expect ( e ) . toEqual ( TransitionSupersededError ) ;
266
+ } ) ;
267
+
268
+ spyOn ( $state , 'go' ) . andCallFake ( function ( state , params , options ) {
269
+ var deferred = $q . defer ( ) ;
270
+
271
+ deferred . reject ( TransitionSupersededError ) ;
272
+ return deferred . promise ;
273
+ } ) ;
274
+
275
+ triggerClick ( el ) ;
276
+ $timeout . flush ( ) ;
277
+ $rootScope . $digest ( ) ;
278
+ } ) ) ;
260
279
} ) ;
261
280
262
281
describe ( 'links in html5 mode' , function ( ) {
@@ -368,7 +387,7 @@ describe('uiStateRef', function() {
368
387
expect ( angular . element ( template [ 0 ] ) . attr ( 'href' ) ) . toBe ( '#/contacts/10' ) ;
369
388
} ) ) ;
370
389
371
- it ( 'accepts option overrides' , inject ( function ( $compile , $timeout , $state ) {
390
+ it ( 'accepts option overrides' , inject ( function ( $compile , $timeout , $state , $q ) {
372
391
var transitionOptions ;
373
392
374
393
el = angular . element ( '<a ui-state="state" ui-state-opts="opts">state</a>' ) ;
@@ -378,7 +397,11 @@ describe('uiStateRef', function() {
378
397
scope . $digest ( ) ;
379
398
380
399
spyOn ( $state , 'go' ) . andCallFake ( function ( state , params , options ) {
400
+ var deferred = $q . defer ( ) ;
401
+
402
+ deferred . resolve ( 42 ) ;
381
403
transitionOptions = options ;
404
+ return deferred . promise ;
382
405
} ) ;
383
406
384
407
triggerClick ( template )
0 commit comments