1
1
import { exec } from '../router.js' ;
2
2
3
+ function doExec ( path , route , opts ) {
4
+ return exec ( path , route , { path, query : { } , params : { } , ...( opts || { } ) } ) ;
5
+ }
6
+
3
7
describe ( 'match' , ( ) => {
4
8
it ( 'Base route' , ( ) => {
5
- const accurateResult = exec ( '/' , '/' , { path : '/' } ) ;
9
+ const accurateResult = doExec ( '/' , '/' ) ;
6
10
expect ( accurateResult ) . toEqual ( { path : '/' , params : { } } ) ;
7
11
8
- const inaccurateResult = exec ( '/user/1' , '/' , { path : '/' } ) ;
12
+ const inaccurateResult = doExec ( '/user/1' , '/' ) ;
9
13
expect ( inaccurateResult ) . toEqual ( undefined ) ;
10
14
} ) ;
11
15
12
16
it ( 'Param route' , ( ) => {
13
- const accurateResult = exec ( '/user/2' , '/user/:id' , { path : '/' } ) ;
17
+ const accurateResult = doExec ( '/user/2' , '/user/:id' ) ;
14
18
expect ( accurateResult ) . toEqual ( { path : '/' , params : { id : '2' } } ) ;
15
19
16
- const inaccurateResult = exec ( '/' , '/user/:id' , { path : '/' } ) ;
20
+ const inaccurateResult = doExec ( '/' , '/user/:id' ) ;
17
21
expect ( inaccurateResult ) . toEqual ( undefined ) ;
18
22
} ) ;
19
23
20
24
it ( 'Optional param route' , ( ) => {
21
- const accurateResult = exec ( '/user' , '/user/:id?' , { path : '/' } ) ;
25
+ const accurateResult = doExec ( '/user' , '/user/:id?' ) ;
22
26
expect ( accurateResult ) . toEqual ( { path : '/' , params : { id : undefined } } ) ;
23
27
24
- const inaccurateResult = exec ( '/' , '/user/:id?' , { path : '/' } ) ;
28
+ const inaccurateResult = doExec ( '/' , '/user/:id?' ) ;
25
29
expect ( inaccurateResult ) . toEqual ( undefined ) ;
26
30
} ) ;
27
31
28
32
it ( 'Handles leading/trailing slashes' , ( ) => {
29
- const result = exec ( '/about-late/_SEGMENT1_/_SEGMENT2_/' , '/about-late/:seg1/:seg2/' , { } ) ;
33
+ const result = doExec ( '/about-late/_SEGMENT1_/_SEGMENT2_/' , '/about-late/:seg1/:seg2/' ) ;
30
34
expect ( result ) . toEqual ( {
31
35
params : {
32
36
seg1 : '_SEGMENT1_' ,
@@ -36,7 +40,7 @@ describe('match', () => {
36
40
} ) ;
37
41
38
42
it ( 'should not overwrite existing properties' , ( ) => {
39
- const result = exec ( '/foo/bar' , '/:path/:query' , { path : '/' } ) ;
43
+ const result = doExec ( '/foo/bar' , '/:path/:query' ) ;
40
44
expect ( result ) . toEqual ( {
41
45
params : { path : 'foo' , query : 'bar' } ,
42
46
path : '/'
0 commit comments