@@ -4,7 +4,9 @@ import { createMatcher } from '../../../src/create-matcher'
44const routes = [
55 { path : '/' , name : 'home' , component : { name : 'home' } } ,
66 { path : '/foo' , name : 'foo' , component : { name : 'foo' } } ,
7- { path : '*' , props : true , component : { name : 'notFound' } }
7+ { path : '/baz/:testparam' , name : 'baz' , component : { name : 'baz' } } ,
8+ { path : '/error/*' , name : 'error' , component : { name : 'error' } } ,
9+ { path : '*' , props : true , name : 'notFound' , component : { name : 'notFound' } }
810]
911
1012describe ( 'Creating Matcher' , function ( ) {
@@ -26,14 +28,49 @@ describe('Creating Matcher', function () {
2628 expect ( matched . length ) . toBe ( 0 )
2729 expect ( name ) . toBe ( 'bar' )
2830 expect ( console . warn ) . toHaveBeenCalled ( )
29- expect ( console . warn . calls . argsFor ( 0 ) [ 0 ] ) . toMatch ( 'Route with name \'bar\' does not exist' )
31+ expect ( console . warn . calls . argsFor ( 0 ) [ 0 ] ) . toMatch (
32+ "Route with name 'bar' does not exist"
33+ )
3034 } )
3135
3236 it ( 'in production, it has not logged this warning' , function ( ) {
3337 match ( { name : 'foo' } , routes [ 0 ] )
3438 expect ( console . warn ) . not . toHaveBeenCalled ( )
3539 } )
3640
41+ it ( 'matches named route with params without warning' , function ( ) {
42+ process . env . NODE_ENV = 'development'
43+ const { name, path, params } = match ( {
44+ name : 'baz' ,
45+ params : { testparam : 'testvalue' }
46+ } )
47+ expect ( console . warn ) . not . toHaveBeenCalled ( )
48+ expect ( name ) . toEqual ( 'baz' )
49+ expect ( path ) . toEqual ( '/baz/testvalue' )
50+ expect ( params ) . toEqual ( { testparam : 'testvalue' } )
51+ } )
52+
53+ it ( 'matches asterisk routes with a default param name without warning' , function ( ) {
54+ process . env . NODE_ENV = 'development'
55+ const { params } = match (
56+ { name : 'notFound' , params : { pathMatch : '/not-found' } } ,
57+ routes [ 0 ]
58+ )
59+ expect ( console . warn ) . not . toHaveBeenCalled ( )
60+ expect ( params ) . toEqual ( { pathMatch : '/not-found' } )
61+ } )
62+
63+ it ( 'matches partial asterisk routes with a default param name without warning' , function ( ) {
64+ process . env . NODE_ENV = 'development'
65+ const { params, path } = match (
66+ { name : 'error' , params : { pathMatch : 'some' } } ,
67+ routes [ 0 ]
68+ )
69+ expect ( console . warn ) . not . toHaveBeenCalled ( )
70+ expect ( params ) . toEqual ( { pathMatch : 'some' } )
71+ expect ( path ) . toEqual ( '/error/some' )
72+ } )
73+
3774 it ( 'matches asterisk routes with a default param name' , function ( ) {
3875 const { params } = match ( { path : '/not-found' } , routes [ 0 ] )
3976 expect ( params ) . toEqual ( { pathMatch : '/not-found' } )
0 commit comments