@@ -57,7 +57,10 @@ describe('state', function () {
57
57
templateParams = params ;
58
58
return "/templates/" + params . item + ".html" ;
59
59
}
60
- } ) ;
60
+ } )
61
+
62
+ . state ( 'first' , { url : '^/first/subpath' } )
63
+ . state ( 'second' , { url : '^/second' } ) ;
61
64
62
65
$provide . value ( 'AppInjectable' , AppInjectable ) ;
63
66
} ) ) ;
@@ -393,17 +396,37 @@ describe('state', function () {
393
396
} ) ;
394
397
395
398
describe ( 'url handling' , function ( ) {
396
-
397
399
it ( 'should transition to the same state with different parameters' , inject ( function ( $state , $rootScope , $location ) {
398
400
$location . path ( "/about/bob" ) ;
399
401
$rootScope . $broadcast ( "$locationChangeSuccess" ) ;
400
402
$rootScope . $apply ( ) ;
401
403
expect ( $state . params ) . toEqual ( { person : "bob" } ) ;
404
+ expect ( $state . current . name ) . toBe ( 'about.person' ) ;
402
405
403
406
$location . path ( "/about/larry" ) ;
404
407
$rootScope . $broadcast ( "$locationChangeSuccess" ) ;
405
408
$rootScope . $apply ( ) ;
406
409
expect ( $state . params ) . toEqual ( { person : "larry" } ) ;
410
+ expect ( $state . current . name ) . toBe ( 'about.person' ) ;
411
+ } ) ) ;
412
+
413
+ it ( 'should correctly handle absolute urls' , inject ( function ( $state , $rootScope , $location ) {
414
+ $location . path ( "/first/subpath" ) ;
415
+ $rootScope . $broadcast ( "$locationChangeSuccess" ) ;
416
+ $rootScope . $apply ( ) ;
417
+ expect ( $state . current . name ) . toBe ( 'first' ) ;
418
+
419
+ $state . transitionTo ( 'second' ) ;
420
+ $rootScope . $apply ( ) ;
421
+ expect ( $state . current . name ) . toBe ( 'second' ) ;
422
+ expect ( $location . path ( ) ) . toBe ( '/second' ) ;
423
+ } ) ) ;
424
+
425
+ it ( 'should ignore bad urls' , inject ( function ( $state , $rootScope , $location ) {
426
+ $location . path ( "/first/second" ) ;
427
+ $rootScope . $broadcast ( "$locationChangeSuccess" ) ;
428
+ $rootScope . $apply ( ) ;
429
+ expect ( $state . current . name ) . toBe ( '' ) ;
407
430
} ) ) ;
408
431
} ) ;
409
432
0 commit comments