@@ -4,6 +4,11 @@ var path = require('path');
44var pkg = require ( '../package.json' ) ;
55var RouteNode = require ( path . join ( __dirname , '..' , pkg . main ) ) ;
66var should = require ( 'should' ) ;
7+ var omit = require ( 'lodash.omit' ) ;
8+
9+ function withoutMeta ( obj ) {
10+ return omit ( obj , '_meta' ) ;
11+ }
712
813require ( 'mocha' ) ;
914
@@ -117,8 +122,19 @@ describe('RouteNode', function () {
117122 it ( 'should find a nested route by matching a path' , function ( ) {
118123 var node = getRoutes ( ) ;
119124 // Building paths
120- node . matchPath ( '/users' ) . should . eql ( { name : 'users' , params : { } } ) ;
121- node . matchPath ( '/users/view/1' ) . should . eql ( { name : 'users.view' , params : { id : '1' } } ) ;
125+ withoutMeta ( node . matchPath ( '/users' ) ) . should . eql ( { name : 'users' , params : { } } ) ;
126+
127+ node . matchPath ( '/users/view/1' ) . should . eql ( {
128+ _meta : {
129+ users : { } ,
130+ view : {
131+ id : 'url'
132+ }
133+ } ,
134+ name : 'users.view' ,
135+ params : { id : '1' }
136+ } ) ;
137+
122138 should . not . exists ( node . matchPath ( '/users/profile/1' ) ) ;
123139 should . not . exists ( node . matchPath ( '/users/view/profile/1' ) ) ;
124140 } ) ;
@@ -142,12 +158,22 @@ describe('RouteNode', function () {
142158 node . buildPath ( 'grandParent.parent.child' , { nickname : [ 'gran' , 'granny' ] } ) . should . equal ( '/grand-parent/parent/child?nickname=gran&nickname=granny' ) ;
143159
144160 // Matching
145- node . matchPath ( '/grand-parent' ) . should . eql ( { name : 'grandParent' , params : { } } ) ;
146- node . matchPath ( '/grand-parent?nickname=gran' ) . should . eql ( { name : 'grandParent' , params : { nickname : 'gran' } } ) ;
147- node . matchPath ( '/grand-parent/parent?nickname=gran&name=maman%20man' ) . should . eql ( { name : 'grandParent.parent' , params : { nickname : 'gran' , name : 'maman man' } } ) ;
148- node . matchPath ( '/grand-parent/parent/child?nickname=gran&name=maman' ) . should . eql ( { name : 'grandParent.parent.child' , params : { nickname : 'gran' , name : 'maman' } } ) ;
149- node . matchPath ( '/grand-parent/parent/child?nickname=gran&name=maman&age=3' ) . should . eql ( { name : 'grandParent.parent.child' , params : { nickname : 'gran' , name : 'maman' , age : '3' } } ) ;
150- node . matchPath ( '/grand-parent/parent/child?nickname=gran&nickname=granny&name=maman&age=3' ) . should . eql ( { name : 'grandParent.parent.child' , params : { nickname : [ 'gran' , 'granny' ] , name : 'maman' , age : '3' } } ) ;
161+ withoutMeta ( node . matchPath ( '/grand-parent' ) ) . should . eql ( { name : 'grandParent' , params : { } } ) ;
162+
163+ node . matchPath ( '/grand-parent?nickname=gran' ) . should . eql ( {
164+ _meta : {
165+ grandParent : {
166+ nickname : 'query'
167+ }
168+ } ,
169+ name : 'grandParent' ,
170+ params : { nickname : 'gran' }
171+ } ) ;
172+
173+ withoutMeta ( node . matchPath ( '/grand-parent/parent?nickname=gran&name=maman%20man' ) ) . should . eql ( { name : 'grandParent.parent' , params : { nickname : 'gran' , name : 'maman man' } } ) ;
174+ withoutMeta ( node . matchPath ( '/grand-parent/parent/child?nickname=gran&name=maman' ) ) . should . eql ( { name : 'grandParent.parent.child' , params : { nickname : 'gran' , name : 'maman' } } ) ;
175+ withoutMeta ( node . matchPath ( '/grand-parent/parent/child?nickname=gran&name=maman&age=3' ) ) . should . eql ( { name : 'grandParent.parent.child' , params : { nickname : 'gran' , name : 'maman' , age : '3' } } ) ;
176+ withoutMeta ( node . matchPath ( '/grand-parent/parent/child?nickname=gran&nickname=granny&name=maman&age=3' ) ) . should . eql ( { name : 'grandParent.parent.child' , params : { nickname : [ 'gran' , 'granny' ] , name : 'maman' , age : '3' } } ) ;
151177
152178 // Unsuccessful matching
153179 should . not . exist ( node . matchPath ( '/grand-parent?nickname=gran&name=papa' ) ) ;
@@ -157,8 +183,8 @@ describe('RouteNode', function () {
157183 it ( 'should find a nested route by matching a path with a splat' , function ( ) {
158184 var node = getRoutesWithSplat ( ) ;
159185 // Building paths
160- node . matchPath ( '/users/view/1' ) . should . eql ( { name : 'users.view' , params : { id : '1' } } ) ;
161- node . matchPath ( '/users/profile/1' ) . should . eql ( { name : 'users.splat' , params : { id : 'profile/1' } } ) ;
186+ withoutMeta ( node . matchPath ( '/users/view/1' ) ) . should . eql ( { name : 'users.view' , params : { id : '1' } } ) ;
187+ withoutMeta ( node . matchPath ( '/users/profile/1' ) ) . should . eql ( { name : 'users.splat' , params : { id : 'profile/1' } } ) ;
162188 should . not . exists ( node . matchPath ( '/users/view/profile/1' ) ) ;
163189 } ) ;
164190
@@ -168,8 +194,8 @@ describe('RouteNode', function () {
168194 new RouteNode ( 'view' , '/view/:id' )
169195 ] ) ;
170196
171- usersNode . matchPath ( '/users/view/1' ) . should . eql ( { name : 'users.view' , params : { id : '1' } } ) ;
172- usersNode . matchPath ( '/users/list' ) . should . eql ( { name : 'users.list' , params : { } } ) ;
197+ withoutMeta ( usersNode . matchPath ( '/users/view/1' ) ) . should . eql ( { name : 'users.view' , params : { id : '1' } } ) ;
198+ withoutMeta ( usersNode . matchPath ( '/users/list' ) ) . should . eql ( { name : 'users.list' , params : { } } ) ;
173199 } )
174200
175201 it ( 'should be able to add deep nodes' , function ( ) {
@@ -190,28 +216,28 @@ describe('RouteNode', function () {
190216 . addNode ( 'abo' , '/abo' )
191217 . addNode ( 'about' , '/about' ) ;
192218
193- rootNode . matchPath ( '/' ) . should . eql ( { name : 'index' , params : { } } ) ;
194- rootNode . matchPath ( '/abo' ) . should . eql ( { name : 'abo' , params : { } } ) ;
195- rootNode . matchPath ( '/about' ) . should . eql ( { name : 'about' , params : { } } ) ;
196- rootNode . matchPath ( '/abc' ) . should . eql ( { name : 'id' , params : { id : 'abc' } } ) ;
197- rootNode . matchPath ( '/section/abc' ) . should . eql ( { name : 'section' , params : { id : 'abc' } } ) ;
219+ withoutMeta ( rootNode . matchPath ( '/' ) ) . should . eql ( { name : 'index' , params : { } } ) ;
220+ withoutMeta ( rootNode . matchPath ( '/abo' ) ) . should . eql ( { name : 'abo' , params : { } } ) ;
221+ withoutMeta ( rootNode . matchPath ( '/about' ) ) . should . eql ( { name : 'about' , params : { } } ) ;
222+ withoutMeta ( rootNode . matchPath ( '/abc' ) ) . should . eql ( { name : 'id' , params : { id : 'abc' } } ) ;
223+ withoutMeta ( rootNode . matchPath ( '/section/abc' ) ) . should . eql ( { name : 'section' , params : { id : 'abc' } } ) ;
198224 } ) ;
199225
200226 it ( 'should match paths with optional trailing slashes' , function ( ) {
201227 var rootNode = getRoutes ( ) ;
202228 should . not . exists ( rootNode . matchPath ( '/users/list/' ) ) ;
203- rootNode . matchPath ( '/users/list' , true ) . should . eql ( { name : 'users.list' , params : { } } ) ;
204- rootNode . matchPath ( '/users/list' ) . should . eql ( { name : 'users.list' , params : { } } ) ;
205- rootNode . matchPath ( '/users/list/' , true ) . should . eql ( { name : 'users.list' , params : { } } ) ;
229+ withoutMeta ( rootNode . matchPath ( '/users/list' , true ) ) . should . eql ( { name : 'users.list' , params : { } } ) ;
230+ withoutMeta ( rootNode . matchPath ( '/users/list' ) ) . should . eql ( { name : 'users.list' , params : { } } ) ;
231+ withoutMeta ( rootNode . matchPath ( '/users/list/' , true ) ) . should . eql ( { name : 'users.list' , params : { } } ) ;
206232 should . not . exists ( rootNode . matchPath ( '/users/list//' , true ) ) ;
207233
208234 var rootNode = getRoutes ( true ) ;
209235 should . not . exists ( rootNode . matchPath ( '/users/list' ) ) ;
210- rootNode . matchPath ( '/users/list' , true ) . should . eql ( { name : 'users.list' , params : { } } ) ;
211- rootNode . matchPath ( '/users/list/' , true ) . should . eql ( { name : 'users.list' , params : { } } ) ;
212- rootNode . matchPath ( '/users/list/' ) . should . eql ( { name : 'users.list' , params : { } } ) ;
213- rootNode . matchPath ( '/' ) . should . eql ( { name : 'default' , params : { } } ) ;
214- rootNode . matchPath ( '' , true ) . should . eql ( { name : 'default' , params : { } } ) ;
236+ withoutMeta ( rootNode . matchPath ( '/users/list' , true ) ) . should . eql ( { name : 'users.list' , params : { } } ) ;
237+ withoutMeta ( rootNode . matchPath ( '/users/list/' , true ) ) . should . eql ( { name : 'users.list' , params : { } } ) ;
238+ withoutMeta ( rootNode . matchPath ( '/users/list/' ) ) . should . eql ( { name : 'users.list' , params : { } } ) ;
239+ withoutMeta ( rootNode . matchPath ( '/' ) ) . should . eql ( { name : 'default' , params : { } } ) ;
240+ withoutMeta ( rootNode . matchPath ( '' , true ) ) . should . eql ( { name : 'default' , params : { } } ) ;
215241 should . not . exists ( rootNode . matchPath ( '/users/list//' , true ) ) ;
216242 } ) ;
217243} ) ;
0 commit comments