1
1
import { exec } from '../router.js' ;
2
2
3
- function execPath ( path , pattern ) {
4
- return exec ( path , pattern , { path } ) ;
3
+ function execPath ( path , pattern , opts ) {
4
+ return exec ( path , pattern , { path, query : { } , params : { } , ... ( opts || { } ) } ) ;
5
5
}
6
6
7
7
describe ( 'match' , ( ) => {
8
8
it ( 'Base route' , ( ) => {
9
9
const accurateResult = execPath ( '/' , '/' ) ;
10
- expect ( accurateResult ) . toEqual ( { path : '/' , params : { } } ) ;
10
+ expect ( accurateResult ) . toEqual ( { path : '/' , params : { } , query : { } } ) ;
11
11
12
12
const inaccurateResult = execPath ( '/user/1' , '/' ) ;
13
13
expect ( inaccurateResult ) . toEqual ( undefined ) ;
14
14
} ) ;
15
15
16
16
it ( 'Param route' , ( ) => {
17
17
const accurateResult = execPath ( '/user/2' , '/user/:id' ) ;
18
- expect ( accurateResult ) . toEqual ( { path : '/user/2' , params : { id : '2' } } ) ;
18
+ expect ( accurateResult ) . toEqual ( { path : '/user/2' , params : { id : '2' } , id : '2' , query : { } } ) ;
19
19
20
20
const inaccurateResult = execPath ( '/' , '/user/:id' ) ;
21
21
expect ( inaccurateResult ) . toEqual ( undefined ) ;
22
22
} ) ;
23
23
24
24
it ( 'Optional param route' , ( ) => {
25
25
const accurateResult = execPath ( '/user' , '/user/:id?' ) ;
26
- expect ( accurateResult ) . toEqual ( { path : '/user' , params : { id : undefined } } ) ;
26
+ expect ( accurateResult ) . toEqual ( { path : '/user' , params : { id : undefined } , id : undefined , query : { } } ) ;
27
27
28
28
const inaccurateResult = execPath ( '/' , '/user/:id?' ) ;
29
29
expect ( inaccurateResult ) . toEqual ( undefined ) ;
30
30
} ) ;
31
31
32
32
it ( 'Optional rest param route "/:x*"' , ( ) => {
33
33
const accurateResult = execPath ( '/user' , '/user/:id?' ) ;
34
- expect ( accurateResult ) . toEqual ( { path : '/user' , params : { id : undefined } } ) ;
34
+ expect ( accurateResult ) . toEqual ( { path : '/user' , params : { id : undefined } , id : undefined , query : { } } ) ;
35
35
36
36
const inaccurateResult = execPath ( '/' , '/user/:id?' ) ;
37
37
expect ( inaccurateResult ) . toEqual ( undefined ) ;
38
38
} ) ;
39
39
40
40
it ( 'Rest param route "/:x+"' , ( ) => {
41
41
const matchedResult = execPath ( '/user/foo' , '/user/:id+' ) ;
42
- expect ( matchedResult ) . toEqual ( { path : '/user/foo' , params : { id : 'foo' } } ) ;
42
+ expect ( matchedResult ) . toEqual ( { path : '/user/foo' , params : { id : 'foo' } , id : 'foo' , query : { } } ) ;
43
43
44
44
const matchedResultWithSlash = execPath ( '/user/foo/bar' , '/user/:id+' ) ;
45
- expect ( matchedResultWithSlash ) . toEqual ( { path : '/user/foo/bar' , params : { id : 'foo/bar' } } ) ;
45
+ expect ( matchedResultWithSlash ) . toEqual ( {
46
+ path : '/user/foo/bar' ,
47
+ params : { id : 'foo/bar' } ,
48
+ id : 'foo/bar' ,
49
+ query : { }
50
+ } ) ;
46
51
47
52
const emptyResult = execPath ( '/user' , '/user/:id+' ) ;
48
53
expect ( emptyResult ) . toEqual ( undefined ) ;
@@ -58,15 +63,19 @@ describe('match', () => {
58
63
params : {
59
64
seg1 : '_SEGMENT1_' ,
60
65
seg2 : '_SEGMENT2_'
61
- }
66
+ } ,
67
+ seg1 : '_SEGMENT1_' ,
68
+ seg2 : '_SEGMENT2_' ,
69
+ query : { }
62
70
} ) ;
63
71
} ) ;
64
72
65
73
it ( 'should not overwrite existing properties' , ( ) => {
66
- const result = exec ( '/foo/bar' , '/:path/:query' , { path : '/custom-path' } ) ;
74
+ const result = execPath ( '/foo/bar' , '/:path/:query' , { path : '/custom-path' } ) ;
67
75
expect ( result ) . toEqual ( {
68
76
params : { path : 'foo' , query : 'bar' } ,
69
- path : '/custom-path'
77
+ path : '/custom-path' ,
78
+ query : { }
70
79
} ) ;
71
80
} ) ;
72
81
} ) ;
0 commit comments