@@ -10,23 +10,31 @@ var App = React.createClass({
10
10
11
11
describe ( 'a Route that matches the URL' , function ( ) {
12
12
it ( 'returns an array' , function ( ) {
13
- var route = Route ( { path : '/a/b/c' , handler : App } ) ;
13
+ var route = TestUtils . renderIntoDocument (
14
+ Route ( { handler : App } ,
15
+ Route ( { path : '/a/b/c' , handler : App } )
16
+ )
17
+ ) ;
14
18
15
19
var matches = route . match ( '/a/b/c' ) ;
16
20
assert ( matches ) ;
17
- expect ( matches . length ) . toEqual ( 1 ) ;
21
+ expect ( matches . length ) . toEqual ( 2 ) ;
18
22
19
23
var rootMatch = getRootMatch ( matches ) ;
20
24
expect ( rootMatch . params ) . toEqual ( { } ) ;
21
25
} ) ;
22
26
23
27
describe ( 'that contains dynamic segments' , function ( ) {
24
28
it ( 'returns an array with the correct params' , function ( ) {
25
- var route = Route ( { path : '/posts/:id/edit' , handler : App } ) ;
29
+ var route = TestUtils . renderIntoDocument (
30
+ Route ( { handler : App } ,
31
+ Route ( { path : '/posts/:id/edit' , handler : App } )
32
+ )
33
+ ) ;
26
34
27
35
var matches = route . match ( '/posts/abc/edit' ) ;
28
36
assert ( matches ) ;
29
- expect ( matches . length ) . toEqual ( 1 ) ;
37
+ expect ( matches . length ) . toEqual ( 2 ) ;
30
38
31
39
var rootMatch = getRootMatch ( matches ) ;
32
40
expect ( rootMatch . params ) . toEqual ( { id : 'abc' } ) ;
@@ -36,38 +44,49 @@ describe('a Route that matches the URL', function () {
36
44
37
45
describe ( 'a Route that does not match the URL' , function ( ) {
38
46
it ( 'returns null' , function ( ) {
39
- var route = Route ( { path : '/a/b/c' , handler : App } ) ;
47
+ var route = TestUtils . renderIntoDocument (
48
+ Route ( { handler : App } ,
49
+ Route ( { path : '/a/b/c' , handler : App } )
50
+ )
51
+ ) ;
52
+
40
53
expect ( route . match ( '/not-found' ) ) . toBe ( null ) ;
41
54
} ) ;
42
55
} ) ;
43
56
44
57
describe ( 'a nested Route that matches the URL' , function ( ) {
45
58
it ( 'returns the appropriate params for each match' , function ( ) {
46
- var route = Route ( { name : 'posts' , path : '/posts/:id' , handler : App } ,
47
- Route ( { name : 'comment' , path : '/posts/:id/comments/:commentId' , handler : App } )
59
+ var route = TestUtils . renderIntoDocument (
60
+ Route ( { handler : App } ,
61
+ Route ( { name : 'posts' , path : '/posts/:id' , handler : App } ,
62
+ Route ( { name : 'comment' , path : '/posts/:id/comments/:commentId' , handler : App } )
63
+ )
64
+ )
48
65
) ;
49
66
50
67
var matches = route . match ( '/posts/abc/comments/123' ) ;
51
68
assert ( matches ) ;
52
- expect ( matches . length ) . toEqual ( 2 ) ;
69
+ expect ( matches . length ) . toEqual ( 3 ) ;
53
70
54
71
var rootMatch = getRootMatch ( matches ) ;
55
72
expect ( rootMatch . route . props . name ) . toEqual ( 'comment' ) ;
56
73
expect ( rootMatch . params ) . toEqual ( { id : 'abc' , commentId : '123' } ) ;
57
74
58
- var firstMatch = matches [ 0 ] ;
59
- expect ( firstMatch . route . props . name ) . toEqual ( 'posts' ) ;
60
- expect ( firstMatch . params ) . toEqual ( { id : 'abc' } ) ;
75
+ var postsMatch = matches [ 1 ] ;
76
+ expect ( postsMatch . route . props . name ) . toEqual ( 'posts' ) ;
77
+ expect ( postsMatch . params ) . toEqual ( { id : 'abc' } ) ;
61
78
} ) ;
62
79
} ) ;
63
80
64
81
describe ( 'multiple nested Router that match the URL' , function ( ) {
65
82
it ( 'returns the first one in the subtree, depth-first' , function ( ) {
66
- var route = Route ( { path : '/' , handler : App } ,
67
- Route ( { path : '/a' , handler : App } ,
68
- Route ( { path : '/a/b' , name : 'expected' , handler : App } )
69
- ) ,
70
- Route ( { path : '/a/b' , handler : App } )
83
+ var route = TestUtils . renderIntoDocument (
84
+ Route ( { handler : App } ,
85
+ Route ( { path : '/a' , handler : App } ,
86
+ Route ( { path : '/a/b' , name : 'expected' , handler : App } )
87
+ ) ,
88
+ Route ( { path : '/a/b' , handler : App } )
89
+ )
71
90
) ;
72
91
73
92
var matches = route . match ( '/a/b' ) ;
@@ -81,12 +100,13 @@ describe('multiple nested Router that match the URL', function () {
81
100
82
101
describe ( 'a Route with custom props' , function ( ) {
83
102
it ( 'receives props' , function ( done ) {
84
- var route = Route ( { handler : App , customProp : 'prop' } ) ;
85
- var component = TestUtils . renderIntoDocument ( route ) ;
103
+ var route = TestUtils . renderIntoDocument (
104
+ Route ( { handler : App , customProp : 'prop' } )
105
+ ) ;
86
106
87
107
route . dispatch ( '/' ) . then ( function ( ) {
88
- assert ( component . props . customProp ) ;
89
- expect ( component . props . customProp ) . toEqual ( 'prop' ) ;
108
+ assert ( route . props . customProp ) ;
109
+ expect ( route . props . customProp ) . toEqual ( 'prop' ) ;
90
110
done ( ) ;
91
111
} ) ;
92
112
} ) ;
0 commit comments