1
+ describe ( "UrlRouter" , function ( ) {
2
+
3
+ var $urp , $ur , location , match , scope ;
4
+
5
+ beforeEach ( function ( ) {
6
+ angular . module ( 'ui.router.test' , function ( ) { } ) . config ( function ( $urlRouterProvider ) {
7
+ $urp = $urlRouterProvider ;
8
+
9
+ $urp . rule ( function ( $injector , $location ) {
10
+ return $location . path ( ) . replace ( 'baz' , 'b4z' ) ;
11
+ } ) . when ( '/foo/:param' , function ( $match ) {
12
+ match = [ '/foo/:param' , $match ] ;
13
+ } ) . when ( '/bar' , function ( $match ) {
14
+ match = [ '/bar' , $match ] ;
15
+ } ) . when ( '/:param' , function ( $match ) {
16
+ match = [ '/:param' , $match ] ;
17
+ } ) ;
18
+ } ) ;
19
+
20
+ module ( 'ui.router' , 'ui.router.test' ) ;
21
+
22
+ inject ( function ( $rootScope , $location , $injector ) {
23
+ scope = $rootScope . $new ( ) ;
24
+ location = $location ;
25
+ $ur = $injector . invoke ( $urp . $get ) ;
26
+ } ) ;
27
+ } ) ;
28
+
29
+ describe ( "provider" , function ( ) {
30
+
31
+ it ( "should throw on non-function rules" , function ( ) {
32
+ expect ( function ( ) { $urp . rule ( null ) ; } ) . toThrow ( "'rule' must be a function" )
33
+ expect ( function ( ) { $urp . otherwise ( null ) ; } ) . toThrow ( "'rule' must be a function" )
34
+ } ) ;
35
+
36
+ } ) ;
37
+
38
+ describe ( "service" , function ( ) {
39
+ it ( "should execute rewrite rules" , function ( ) {
40
+ location . path ( "/foo" ) ;
41
+ scope . $emit ( "$locationChangeSuccess" ) ;
42
+ expect ( location . path ( ) ) . toBe ( "/foo" ) ;
43
+
44
+ location . path ( "/baz" ) ;
45
+ scope . $emit ( "$locationChangeSuccess" ) ;
46
+ expect ( location . path ( ) ) . toBe ( "/b4z" ) ;
47
+ } ) ;
48
+ } ) ;
49
+
50
+ } ) ;
0 commit comments