@@ -7,13 +7,13 @@ describe("UrlRouter", function () {
77 $urp = $urlRouterProvider ;
88
99 $urp . rule ( function ( $injector , $location ) {
10- return $location . path ( ) . replace ( 'baz' , 'b4z' ) ;
10+ var path = $location . path ( ) ;
11+ if ( ! / b a z / . test ( path ) ) return false ;
12+ return path . replace ( 'baz' , 'b4z' ) ;
1113 } ) . when ( '/foo/:param' , function ( $match ) {
1214 match = [ '/foo/:param' , $match ] ;
1315 } ) . when ( '/bar' , function ( $match ) {
1416 match = [ '/bar' , $match ] ;
15- } ) . when ( '/:param' , function ( $match ) {
16- match = [ '/:param' , $match ] ;
1717 } ) ;
1818 } ) ;
1919
@@ -45,6 +45,22 @@ describe("UrlRouter", function () {
4545 scope . $emit ( "$locationChangeSuccess" ) ;
4646 expect ( location . path ( ) ) . toBe ( "/b4z" ) ;
4747 } ) ;
48+
49+ it ( "should keep otherwise last" , function ( ) {
50+ $urp . otherwise ( '/otherwise' ) ;
51+
52+ location . path ( "/lastrule" ) ;
53+ scope . $emit ( "$locationChangeSuccess" ) ;
54+ expect ( location . path ( ) ) . toBe ( "/otherwise" ) ;
55+
56+ $urp . when ( '/lastrule' , function ( $match ) {
57+ match = [ '/lastrule' , $match ] ;
58+ } ) ;
59+
60+ location . path ( "/lastrule" ) ;
61+ scope . $emit ( "$locationChangeSuccess" ) ;
62+ expect ( location . path ( ) ) . toBe ( "/lastrule" ) ;
63+ } ) ;
4864 } ) ;
4965
50- } ) ;
66+ } ) ;
0 commit comments