@@ -4,7 +4,9 @@ import { createMatcher } from '../../../src/create-matcher'
4
4
const routes = [
5
5
{ path : '/' , name : 'home' , component : { name : 'home' } } ,
6
6
{ 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' } }
8
10
]
9
11
10
12
describe ( 'Creating Matcher' , function ( ) {
@@ -26,14 +28,49 @@ describe('Creating Matcher', function () {
26
28
expect ( matched . length ) . toBe ( 0 )
27
29
expect ( name ) . toBe ( 'bar' )
28
30
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
+ )
30
34
} )
31
35
32
36
it ( 'in production, it has not logged this warning' , function ( ) {
33
37
match ( { name : 'foo' } , routes [ 0 ] )
34
38
expect ( console . warn ) . not . toHaveBeenCalled ( )
35
39
} )
36
40
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
+
37
74
it ( 'matches asterisk routes with a default param name' , function ( ) {
38
75
const { params } = match ( { path : '/not-found' } , routes [ 0 ] )
39
76
expect ( params ) . toEqual ( { pathMatch : '/not-found' } )
0 commit comments