11require ( './helper' ) ;
22var Route = require ( '../modules/components/Route' ) ;
33var Routes = require ( '../modules/components/Routes' ) ;
4+ var URLStore = require ( '../modules/stores/URLStore' ) ;
45
56var App = React . createClass ( {
67 displayName : 'App' ,
@@ -9,113 +10,122 @@ var App = React.createClass({
910 }
1011} ) ;
1112
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 ( ) {
2814
29- removeComponent ( routes ) ;
15+ afterEach ( function ( ) {
16+ URLStore . teardown ( ) ;
17+ window . location . hash = '' ;
3018 } ) ;
3119
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 ( ) {
3422 var routes = renderComponent (
3523 Routes ( null ,
3624 Route ( { handler : App } ,
37- Route ( { path : '/posts/:id/edit ' , handler : App } )
25+ Route ( { path : '/a/b/c ' , handler : App } )
3826 )
3927 )
4028 ) ;
4129
42- var matches = routes . match ( '/posts/abc/edit ' ) ;
30+ var matches = routes . match ( '/a/b/c ' ) ;
4331 assert ( matches ) ;
4432 expect ( matches . length ) . toEqual ( 2 ) ;
4533
4634 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' } ) ;
4857
49- removeComponent ( routes ) ;
58+ //removeComponent(routes);
59+ } ) ;
5060 } ) ;
5161 } ) ;
52- } ) ;
5362
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+ )
6070 )
61- )
62- ) ;
71+ ) ;
6372
64- expect ( routes . match ( '/not-found' ) ) . toBe ( null ) ;
73+ expect ( routes . match ( '/not-found' ) ) . toBe ( null ) ;
6574
66- removeComponent ( routes ) ;
75+ //removeComponent(routes);
76+ } ) ;
6777 } ) ;
68- } ) ;
6978
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+ )
7787 )
7888 )
79- )
80- ) ;
89+ ) ;
8190
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 ) ;
8594
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' } ) ;
8998
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' } ) ;
93102
94- removeComponent ( routes ) ;
103+ //removeComponent(routes);
104+ } ) ;
95105 } ) ;
96- } ) ;
97106
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+ )
107117 )
108- )
109- ) ;
118+ ) ;
110119
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 ) ;
114123
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' ) ;
117126
118- removeComponent ( routes ) ;
127+ //removeComponent(routes);
128+ } ) ;
119129 } ) ;
120130} ) ;
121131
0 commit comments