This repository was archived by the owner on Jun 27, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +264
-149
lines changed
Expand file tree Collapse file tree 5 files changed +264
-149
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import { runner } from './setup/runner'
2+
3+ runner ( 'Path' , [
4+ {
5+ given : '/user/:userId' ,
6+ when : [
7+ {
8+ actual : '/user/abc-123' ,
9+ it : {
10+ matches : true ,
11+ params : { userId : 'abc-123' } ,
12+ } ,
13+ } ,
14+ {
15+ actual : '/user/abc-123/' ,
16+ it : {
17+ matches : true ,
18+ params : { userId : 'abc-123' } ,
19+ } ,
20+ } ,
21+ {
22+ actual : '/user/' ,
23+ it : {
24+ matches : false ,
25+ params : null ,
26+ } ,
27+ } ,
28+ {
29+ actual : '/user/abc-123/messages' ,
30+ it : {
31+ matches : false ,
32+ params : null ,
33+ } ,
34+ } ,
35+ {
36+ actual : '/arbitrary/abc-123' ,
37+ it : {
38+ matches : false ,
39+ params : null ,
40+ } ,
41+ } ,
42+ ] ,
43+ } ,
44+ {
45+ given : '/user/:userId/messages' ,
46+ when : [
47+ {
48+ actual : '/user/abc-123/messages' ,
49+ it : {
50+ matches : true ,
51+ params : {
52+ userId : 'abc-123' ,
53+ } ,
54+ } ,
55+ } ,
56+ {
57+ actual : '/user/abc-123/messages/arbitrary' ,
58+ it : {
59+ matches : false ,
60+ params : null ,
61+ } ,
62+ } ,
63+ {
64+ actual : '/user/abc-123/' ,
65+ it : {
66+ matches : false ,
67+ params : null ,
68+ } ,
69+ } ,
70+ ] ,
71+ } ,
72+ {
73+ given : '/user/*/messages' ,
74+ when : [
75+ {
76+ actual : '/user/arbitrary/messages' ,
77+ it : {
78+ matches : true ,
79+ params : null ,
80+ } ,
81+ } ,
82+ {
83+ actual : '/user/arbitrary/messages/more' ,
84+ it : {
85+ matches : false ,
86+ params : null ,
87+ } ,
88+ } ,
89+ {
90+ actual : '/user/' ,
91+ it : {
92+ matches : false ,
93+ params : null ,
94+ } ,
95+ } ,
96+ ] ,
97+ } ,
98+ ] )
Original file line number Diff line number Diff line change 1+ import { runner } from './setup/runner'
2+
3+ runner ( 'RegExp' , [
4+ {
5+ given : / \/ u s e r s \/ / ,
6+ when : [
7+ {
8+ actual : '/users/' ,
9+ it : {
10+ matches : true ,
11+ params : null ,
12+ } ,
13+ } ,
14+ {
15+ actual : '/users/abcd-1234/' ,
16+ it : {
17+ matches : true ,
18+ params : null ,
19+ } ,
20+ } ,
21+ {
22+ actual : '/settings' ,
23+ it : {
24+ matches : false ,
25+ params : null ,
26+ } ,
27+ } ,
28+ ] ,
29+ } ,
30+ {
31+ given : / \/ u s e r \/ .+ ?\/ / ,
32+ when : [
33+ {
34+ actual : '/user/abcd-1234/' ,
35+ it : {
36+ matches : true ,
37+ params : null ,
38+ } ,
39+ } ,
40+ {
41+ actual : '/user/' ,
42+ it : {
43+ matches : false ,
44+ params : null ,
45+ } ,
46+ } ,
47+ ] ,
48+ } ,
49+ ] )
Original file line number Diff line number Diff line change 1+ import { Path , match } from '../../src/match'
2+
3+ export interface Scenario {
4+ given : Path
5+ when : Array < {
6+ actual : string
7+ it : {
8+ [ key : string ] : any
9+ } & ReturnType < typeof match >
10+ } >
11+ }
12+
13+ export const runner = ( name : string , scenarios : Scenario [ ] ) => {
14+ describe ( name , ( ) => {
15+ scenarios . forEach ( ( scenario ) => {
16+ describe ( `given "${ scenario . given } " path` , ( ) => {
17+ scenario . when . forEach ( ( data ) => {
18+ describe ( `and "${ data . actual } " url` , ( ) => {
19+ let result : ReturnType < typeof match >
20+
21+ beforeAll ( ( ) => {
22+ result = match ( scenario . given , data . actual )
23+ } )
24+
25+ Object . entries ( data . it ) . forEach ( ( [ key , expectedValue ] ) => {
26+ it ( `"${ key } ": "${ JSON . stringify ( expectedValue ) } "` , ( ) => {
27+ expect ( result ) . toHaveProperty ( key , expectedValue )
28+ } )
29+ } )
30+ } )
31+ } )
32+ } )
33+ } )
34+ } )
35+ }
You can’t perform that action at this time.
0 commit comments