@@ -47,91 +47,92 @@ expectType<{
4747
4848describe ( 'insertParamsIntoPath' , ( ) => {
4949 it ( 'should insert params into path' , ( ) => {
50- const path = '/post/:id/comments/:commentId' ;
51-
52- const params = {
53- commentId : '2' ,
54- id : '1' ,
55- } ;
56-
57- const result = insertParamsIntoPath ( { path, params } ) ;
58-
59- expect ( result ) . toBe ( '/post/1/comments/2' ) ;
50+ expect (
51+ insertParamsIntoPath ( {
52+ path : '/post/:id/comments/:commentId' ,
53+ params : { commentId : '2' , id : '1' } ,
54+ } ) ,
55+ ) . toBe ( '/post/1/comments/2' ) ;
6056 } ) ;
6157
6258 it ( 'should insert params into path with no params' , ( ) => {
63- const path = '/posts' ;
64-
65- const result = insertParamsIntoPath ( { path, params : { } } ) ;
66-
67- expect ( result ) . toBe ( '/posts' ) ;
59+ expect (
60+ insertParamsIntoPath ( {
61+ path : '/posts' ,
62+ params : { a : '1' } ,
63+ } ) ,
64+ ) . toBe ( '/posts' ) ;
6865 } ) ;
6966
7067 it ( 'should insert params into path with many params' , ( ) => {
71- const path = '/post/:id/comments/:commentId/:commentId2' ;
72-
73- const params = {
74- commentId : '2' ,
75- commentId2 : '3' ,
76- id : '1' ,
77- } ;
78-
79- const result = insertParamsIntoPath ( { path, params } ) ;
80-
81- expect ( result ) . toBe ( '/post/1/comments/2/3' ) ;
68+ expect (
69+ insertParamsIntoPath ( {
70+ path : '/post/:id/comments/:commentId/:commentId2' ,
71+ params : { commentId : '2' , commentId2 : '3' , id : '1' } ,
72+ } ) ,
73+ ) . toBe ( '/post/1/comments/2/3' ) ;
8274 } ) ;
8375
8476 it ( 'should insert into paths with only one param' , ( ) => {
85- const path = '/:id' ;
86-
87- const params = {
88- id : '1' ,
89- } ;
90-
91- const result = insertParamsIntoPath ( { path, params } ) ;
92-
93- expect ( result ) . toBe ( '/1' ) ;
77+ expect (
78+ insertParamsIntoPath ( {
79+ path : '/:id' ,
80+ params : { id : '1' } ,
81+ } ) ,
82+ ) . toBe ( '/1' ) ;
9483 } ) ;
9584
9685 it ( 'should insert optional params into path with many params' , ( ) => {
97- const path = '/post/:id?/comments/:commentId?/:commentId2?' ;
98-
99- const params = {
100- commentId : '2' ,
101- commentId2 : '3' ,
102- id : '1' ,
103- } ;
104-
105- const result = insertParamsIntoPath ( { path, params } ) ;
106-
107- expect ( result ) . toBe ( '/post/1/comments/2/3' ) ;
86+ expect (
87+ insertParamsIntoPath ( {
88+ path : '/post/:id?/comments/:commentId?/:commentId2?' ,
89+ params : { commentId : '2' , commentId2 : '3' , id : '1' } ,
90+ } ) ,
91+ ) . toBe ( '/post/1/comments/2/3' ) ;
10892 } ) ;
10993
11094 it ( 'should insert optional params into path with no params' , ( ) => {
111- const path = '/post/:id?/comments/:commentId?/:commentId2?' ;
112-
113- const result = insertParamsIntoPath ( { path, params : { } } ) ;
114-
115- expect ( result ) . toBe ( '/post/comments' ) ;
95+ expect (
96+ insertParamsIntoPath ( {
97+ path : '/post/:id?/comments/:commentId?/:commentId2?' ,
98+ params : { } ,
99+ } ) ,
100+ ) . toBe ( '/post/comments' ) ;
116101 } ) ;
117102
118103 it ( 'should insert not have trailing slashes' , ( ) => {
119- const path = '/post/:id?/comments/:commentId?/:commentId2?/:commentId3?' ;
120-
121- const result = insertParamsIntoPath ( { path, params : { } } ) ;
122-
123- expect ( result ) . toBe ( '/post/comments' ) ;
104+ expect (
105+ insertParamsIntoPath ( {
106+ path : '/post/:id?/comments/:commentId?/:commentId2?/:commentId3?' ,
107+ params : { } ,
108+ } ) ,
109+ ) . toBe ( '/post/comments' ) ;
124110 } ) ;
125111
126112 it ( 'should insert optional params into paths with only one param' , ( ) => {
127- const path = '/:id?' ;
128-
129- const params = {
130- id : '1' ,
131- } ;
113+ expect (
114+ insertParamsIntoPath ( {
115+ path : '/:id?' ,
116+ params : { id : '1' } ,
117+ } ) ,
118+ ) . toBe ( '/1' ) ;
119+ } ) ;
132120
133- const result = insertParamsIntoPath ( { path, params } ) ;
121+ it ( 'should preserve trailing slashes in path' , ( ) => {
122+ expect (
123+ insertParamsIntoPath ( {
124+ path : '/:id/' ,
125+ params : { id : '1' } ,
126+ } ) ,
127+ ) . toBe ( '/1/' ) ;
128+ } ) ;
134129
135- expect ( result ) . toBe ( '/1' ) ;
130+ it ( 'should preserve trailing slashes in path with optional params' , ( ) => {
131+ expect (
132+ insertParamsIntoPath ( {
133+ path : '/post/:id?/comments/:commentId?/:commentId2?/:commentId3?/' ,
134+ params : { } ,
135+ } ) ,
136+ ) . toBe ( '/post/comments/' ) ;
136137 } ) ;
137138} ) ;
0 commit comments