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' ) ;
5
4
6
5
var App = React . createClass ( {
7
6
displayName : 'App' ,
@@ -10,16 +9,11 @@ var App = React.createClass({
10
9
}
11
10
} ) ;
12
11
13
- describe ( 'Route' , function ( ) {
12
+ describe ( 'a Route' , function ( ) {
14
13
15
- afterEach ( function ( ) {
16
- URLStore . teardown ( ) ;
17
- window . location . hash = '' ;
18
- } ) ;
19
-
20
- describe ( 'a Route that matches a URL' , function ( ) {
14
+ describe ( 'that matches the URL' , function ( ) {
21
15
it ( 'returns an array' , function ( ) {
22
- var routes = renderComponent (
16
+ var routes = ReactTestUtils . renderIntoDocument (
23
17
Routes ( null ,
24
18
Route ( { handler : App } ,
25
19
Route ( { path : '/a/b/c' , handler : App } )
@@ -33,14 +27,11 @@ describe('Route', function() {
33
27
34
28
var rootMatch = getRootMatch ( matches ) ;
35
29
expect ( rootMatch . params ) . toEqual ( { } ) ;
36
-
37
- // this causes tests to fail, no clue why ...
38
- //removeComponent(routes);
39
30
} ) ;
40
31
41
32
describe ( 'that contains dynamic segments' , function ( ) {
42
33
it ( 'returns an array with the correct params' , function ( ) {
43
- var routes = renderComponent (
34
+ var routes = ReactTestUtils . renderIntoDocument (
44
35
Routes ( null ,
45
36
Route ( { handler : App } ,
46
37
Route ( { path : '/posts/:id/edit' , handler : App } )
@@ -54,15 +45,13 @@ describe('Route', function() {
54
45
55
46
var rootMatch = getRootMatch ( matches ) ;
56
47
expect ( rootMatch . params ) . toEqual ( { id : 'abc' } ) ;
57
-
58
- //removeComponent(routes);
59
48
} ) ;
60
49
} ) ;
61
50
} ) ;
62
51
63
- describe ( 'a Route that does not match the URL' , function ( ) {
52
+ describe ( 'that does not match the URL' , function ( ) {
64
53
it ( 'returns null' , function ( ) {
65
- var routes = renderComponent (
54
+ var routes = ReactTestUtils . renderIntoDocument (
66
55
Routes ( null ,
67
56
Route ( { handler : App } ,
68
57
Route ( { path : '/a/b/c' , handler : App } )
@@ -71,103 +60,59 @@ describe('Route', function() {
71
60
) ;
72
61
73
62
expect ( routes . match ( '/not-found' ) ) . toBe ( null ) ;
74
-
75
- //removeComponent(routes);
76
63
} ) ;
77
64
} ) ;
78
65
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
- )
66
+ } ) ;
67
+
68
+ describe ( 'a nested Route that matches the URL' , function ( ) {
69
+ it ( 'returns the appropriate params for each match' , function ( ) {
70
+ var routes = ReactTestUtils . renderIntoDocument (
71
+ Routes ( null ,
72
+ Route ( { handler : App } ,
73
+ Route ( { name : 'posts' , path : '/posts/:id' , handler : App } ,
74
+ Route ( { name : 'comment' , path : '/posts/:id/comments/:commentId' , handler : App } )
87
75
)
88
76
)
89
- ) ;
77
+ )
78
+ ) ;
90
79
91
- var matches = routes . match ( '/posts/abc/comments/123' ) ;
92
- assert ( matches ) ;
93
- expect ( matches . length ) . toEqual ( 3 ) ;
80
+ var matches = routes . match ( '/posts/abc/comments/123' ) ;
81
+ assert ( matches ) ;
82
+ expect ( matches . length ) . toEqual ( 3 ) ;
94
83
95
- var rootMatch = getRootMatch ( matches ) ;
96
- expect ( rootMatch . route . props . name ) . toEqual ( 'comment' ) ;
97
- expect ( rootMatch . params ) . toEqual ( { id : 'abc' , commentId : '123' } ) ;
84
+ var rootMatch = getRootMatch ( matches ) ;
85
+ expect ( rootMatch . route . props . name ) . toEqual ( 'comment' ) ;
86
+ expect ( rootMatch . params ) . toEqual ( { id : 'abc' , commentId : '123' } ) ;
98
87
99
- var postsMatch = matches [ 1 ] ;
100
- expect ( postsMatch . route . props . name ) . toEqual ( 'posts' ) ;
101
- expect ( postsMatch . params ) . toEqual ( { id : 'abc' } ) ;
102
-
103
- //removeComponent(routes);
104
- } ) ;
88
+ var postsMatch = matches [ 1 ] ;
89
+ expect ( postsMatch . route . props . name ) . toEqual ( 'posts' ) ;
90
+ expect ( postsMatch . params ) . toEqual ( { id : 'abc' } ) ;
105
91
} ) ;
92
+ } ) ;
106
93
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
- )
94
+ describe ( 'multiple nested Routes that match the URL' , function ( ) {
95
+ it ( 'returns the first one in the subtree, depth-first' , function ( ) {
96
+ var routes = ReactTestUtils . renderIntoDocument (
97
+ Routes ( null ,
98
+ Route ( { handler : App } ,
99
+ Route ( { path : '/a' , handler : App } ,
100
+ Route ( { path : '/a/b' , name : 'expected' , handler : App } )
101
+ ) ,
102
+ Route ( { path : '/a/b' , handler : App } )
117
103
)
118
- ) ;
119
-
120
- var matches = routes . match ( '/a/b' ) ;
121
- assert ( matches ) ;
122
- expect ( matches . length ) . toEqual ( 3 ) ;
104
+ )
105
+ ) ;
123
106
124
- var rootMatch = getRootMatch ( matches ) ;
125
- expect ( rootMatch . route . props . name ) . toEqual ( 'expected' ) ;
107
+ var matches = routes . match ( '/a/b' ) ;
108
+ assert ( matches ) ;
109
+ expect ( matches . length ) . toEqual ( 3 ) ;
126
110
127
- //removeComponent(routes );
128
- } ) ;
111
+ var rootMatch = getRootMatch ( matches ) ;
112
+ expect ( rootMatch . route . props . name ) . toEqual ( 'expected' ) ;
129
113
} ) ;
130
114
} ) ;
131
115
132
- // describe('a Router that renders on the server', function() {
133
- // it('works with async willTransitionTo()', function(done) {
134
- // var dataStore = 'goodbye';
135
- // var Layout = React.createClass({
136
- // render: function() {
137
- // return React.DOM.article(null, this.props.activeRouteHandler());
138
- // }
139
- // });
140
- // var AsyncApp = React.createClass({
141
- // displayName: 'AsyncApp',
142
- // statics: {
143
- // willTransitionTo: function() {
144
- // return new Promise(function(resolve) {
145
- // setTimeout(function() {
146
- // dataStore = 'hello';
147
- // resolve();
148
- // }, 0);
149
- // });
150
- // }
151
- // },
152
- // render: function() {
153
- // return React.DOM.div(null, dataStore);
154
- // }
155
- // });
156
-
157
- // var router = Router(
158
- // RouteComponent({ handler: Layout},
159
- // RouteComponent({ path: '/a', handler: AsyncApp }))
160
- // );
161
-
162
- // router.renderComponentToString('/a').then(function(result) {
163
- // expect(result.indexOf('div') > -1).toBe(true);
164
- // expect(result.indexOf('hello') > -1).toBe(true);
165
-
166
- // done();
167
- // });
168
- // });
169
- // });
170
-
171
116
function getRootMatch ( matches ) {
172
117
return matches [ matches . length - 1 ] ;
173
118
}
0 commit comments