1
1
require ( './helper' ) ;
2
2
var Route = require ( '../modules/components/Route' ) ;
3
3
var Routes = require ( '../modules/components/Routes' ) ;
4
+ var URLStore = require ( '../modules/stores/URLStore' ) ;
4
5
5
6
var App = React . createClass ( {
6
7
displayName : 'App' ,
@@ -9,113 +10,122 @@ var App = React.createClass({
9
10
}
10
11
} ) ;
11
12
12
- describe ( 'a Route that matches a URL' , function ( ) {
13
- it ( 'returns an array' , function ( ) {
14
- var routes = renderComponent (
15
- Routes ( null ,
16
- Route ( { handler : App } ,
17
- Route ( { path : '/a/b/c' , handler : App } )
18
- )
19
- )
20
- ) ;
21
-
22
- var matches = routes . match ( '/a/b/c' ) ;
23
- assert ( matches ) ;
24
- expect ( matches . length ) . toEqual ( 2 ) ;
25
-
26
- var rootMatch = getRootMatch ( matches ) ;
27
- expect ( rootMatch . params ) . toEqual ( { } ) ;
13
+ describe ( 'Route' , function ( ) {
28
14
29
- removeComponent ( routes ) ;
15
+ afterEach ( function ( ) {
16
+ URLStore . teardown ( ) ;
17
+ window . location . hash = '' ;
30
18
} ) ;
31
19
32
- describe ( 'that contains dynamic segments ' , function ( ) {
33
- it ( 'returns an array with the correct params ' , function ( ) {
20
+ describe ( 'a Route that matches a URL ' , function ( ) {
21
+ it ( 'returns an array' , function ( ) {
34
22
var routes = renderComponent (
35
23
Routes ( null ,
36
24
Route ( { handler : App } ,
37
- Route ( { path : '/posts/:id/edit ' , handler : App } )
25
+ Route ( { path : '/a/b/c ' , handler : App } )
38
26
)
39
27
)
40
28
) ;
41
29
42
- var matches = routes . match ( '/posts/abc/edit ' ) ;
30
+ var matches = routes . match ( '/a/b/c ' ) ;
43
31
assert ( matches ) ;
44
32
expect ( matches . length ) . toEqual ( 2 ) ;
45
33
46
34
var rootMatch = getRootMatch ( matches ) ;
47
- expect ( rootMatch . params ) . toEqual ( { id : 'abc' } ) ;
35
+ expect ( rootMatch . params ) . toEqual ( { } ) ;
36
+
37
+ // this causes tests to fail, no clue why ...
38
+ //removeComponent(routes);
39
+ } ) ;
40
+
41
+ describe ( 'that contains dynamic segments' , function ( ) {
42
+ it ( 'returns an array with the correct params' , function ( ) {
43
+ var routes = renderComponent (
44
+ Routes ( null ,
45
+ Route ( { handler : App } ,
46
+ Route ( { path : '/posts/:id/edit' , handler : App } )
47
+ )
48
+ )
49
+ ) ;
50
+
51
+ var matches = routes . match ( '/posts/abc/edit' ) ;
52
+ assert ( matches ) ;
53
+ expect ( matches . length ) . toEqual ( 2 ) ;
54
+
55
+ var rootMatch = getRootMatch ( matches ) ;
56
+ expect ( rootMatch . params ) . toEqual ( { id : 'abc' } ) ;
48
57
49
- removeComponent ( routes ) ;
58
+ //removeComponent(routes);
59
+ } ) ;
50
60
} ) ;
51
61
} ) ;
52
- } ) ;
53
62
54
- describe ( 'a Route that does not match the URL' , function ( ) {
55
- it ( 'returns null' , function ( ) {
56
- var routes = renderComponent (
57
- Routes ( null ,
58
- Route ( { handler : App } ,
59
- Route ( { path : '/a/b/c' , handler : App } )
63
+ describe ( 'a Route that does not match the URL' , function ( ) {
64
+ it ( 'returns null' , function ( ) {
65
+ var routes = renderComponent (
66
+ Routes ( null ,
67
+ Route ( { handler : App } ,
68
+ Route ( { path : '/a/b/c' , handler : App } )
69
+ )
60
70
)
61
- )
62
- ) ;
71
+ ) ;
63
72
64
- expect ( routes . match ( '/not-found' ) ) . toBe ( null ) ;
73
+ expect ( routes . match ( '/not-found' ) ) . toBe ( null ) ;
65
74
66
- removeComponent ( routes ) ;
75
+ //removeComponent(routes);
76
+ } ) ;
67
77
} ) ;
68
- } ) ;
69
78
70
- describe ( 'a nested Route that matches the URL' , function ( ) {
71
- it ( 'returns the appropriate params for each match' , function ( ) {
72
- var routes = renderComponent (
73
- Routes ( null ,
74
- Route ( { handler : App } ,
75
- Route ( { name : 'posts' , path : '/posts/:id' , handler : App } ,
76
- Route ( { name : 'comment' , path : '/posts/:id/comments/:commentId' , handler : App } )
79
+ describe ( 'a nested Route that matches the URL' , function ( ) {
80
+ it ( 'returns the appropriate params for each match' , function ( ) {
81
+ var routes = renderComponent (
82
+ Routes ( null ,
83
+ Route ( { handler : App } ,
84
+ Route ( { name : 'posts' , path : '/posts/:id' , handler : App } ,
85
+ Route ( { name : 'comment' , path : '/posts/:id/comments/:commentId' , handler : App } )
86
+ )
77
87
)
78
88
)
79
- )
80
- ) ;
89
+ ) ;
81
90
82
- var matches = routes . match ( '/posts/abc/comments/123' ) ;
83
- assert ( matches ) ;
84
- expect ( matches . length ) . toEqual ( 3 ) ;
91
+ var matches = routes . match ( '/posts/abc/comments/123' ) ;
92
+ assert ( matches ) ;
93
+ expect ( matches . length ) . toEqual ( 3 ) ;
85
94
86
- var rootMatch = getRootMatch ( matches ) ;
87
- expect ( rootMatch . route . props . name ) . toEqual ( 'comment' ) ;
88
- expect ( rootMatch . params ) . toEqual ( { id : 'abc' , commentId : '123' } ) ;
95
+ var rootMatch = getRootMatch ( matches ) ;
96
+ expect ( rootMatch . route . props . name ) . toEqual ( 'comment' ) ;
97
+ expect ( rootMatch . params ) . toEqual ( { id : 'abc' , commentId : '123' } ) ;
89
98
90
- var postsMatch = matches [ 1 ] ;
91
- expect ( postsMatch . route . props . name ) . toEqual ( 'posts' ) ;
92
- expect ( postsMatch . params ) . toEqual ( { id : 'abc' } ) ;
99
+ var postsMatch = matches [ 1 ] ;
100
+ expect ( postsMatch . route . props . name ) . toEqual ( 'posts' ) ;
101
+ expect ( postsMatch . params ) . toEqual ( { id : 'abc' } ) ;
93
102
94
- removeComponent ( routes ) ;
103
+ //removeComponent(routes);
104
+ } ) ;
95
105
} ) ;
96
- } ) ;
97
106
98
- describe ( 'multiple nested Router that match the URL' , function ( ) {
99
- it ( 'returns the first one in the subtree, depth-first' , function ( ) {
100
- var routes = renderComponent (
101
- Routes ( null ,
102
- Route ( { handler : App } ,
103
- Route ( { path : '/a' , handler : App } ,
104
- Route ( { path : '/a/b' , name : 'expected' , handler : App } )
105
- ) ,
106
- Route ( { path : '/a/b' , handler : App } )
107
+ describe ( 'multiple nested Router that match the URL' , function ( ) {
108
+ it ( 'returns the first one in the subtree, depth-first' , function ( ) {
109
+ var routes = renderComponent (
110
+ Routes ( null ,
111
+ Route ( { handler : App } ,
112
+ Route ( { path : '/a' , handler : App } ,
113
+ Route ( { path : '/a/b' , name : 'expected' , handler : App } )
114
+ ) ,
115
+ Route ( { path : '/a/b' , handler : App } )
116
+ )
107
117
)
108
- )
109
- ) ;
118
+ ) ;
110
119
111
- var matches = routes . match ( '/a/b' ) ;
112
- assert ( matches ) ;
113
- expect ( matches . length ) . toEqual ( 3 ) ;
120
+ var matches = routes . match ( '/a/b' ) ;
121
+ assert ( matches ) ;
122
+ expect ( matches . length ) . toEqual ( 3 ) ;
114
123
115
- var rootMatch = getRootMatch ( matches ) ;
116
- expect ( rootMatch . route . props . name ) . toEqual ( 'expected' ) ;
124
+ var rootMatch = getRootMatch ( matches ) ;
125
+ expect ( rootMatch . route . props . name ) . toEqual ( 'expected' ) ;
117
126
118
- removeComponent ( routes ) ;
127
+ //removeComponent(routes);
128
+ } ) ;
119
129
} ) ;
120
130
} ) ;
121
131
0 commit comments