@@ -60,6 +60,11 @@ describe('MatcherPatternPathStatic', () => {
6060 const pattern = new MatcherPatternPathStatic ( '/Team' )
6161 expect ( pattern . build ( ) ) . toBe ( '/Team' )
6262 } )
63+
64+ it ( 'preserves trailing slash' , ( ) => {
65+ const pattern = new MatcherPatternPathStatic ( '/team/' )
66+ expect ( pattern . build ( ) ) . toBe ( '/team/' )
67+ } )
6368 } )
6469} )
6570
@@ -213,7 +218,7 @@ describe('MatcherPatternPathDynamic', () => {
213218 expect ( pattern . build ( { teamId : [ '123' , '456' ] } ) ) . toBe ( '/teams/123/456/b' )
214219 } )
215220
216- it ( 'catch all route' , ( ) => {
221+ it . todo ( 'catch all route' , ( ) => {
217222 // const pattern = new MatcherPatternPathDynamic(
218223 } )
219224
@@ -302,4 +307,78 @@ describe('MatcherPatternPathDynamic', () => {
302307 '/teams/123-b-456'
303308 )
304309 } )
310+
311+ it ( 'can have a trailing slash after a single param' , ( ) => {
312+ const pattern = new MatcherPatternPathDynamic (
313+ / ^ \/ t e a m s \/ ( [ ^ / ] + ?) \/ $ / i,
314+ {
315+ teamId : { } ,
316+ } ,
317+ [ 'teams' , [ 0 , '/' ] ]
318+ )
319+
320+ expect ( pattern . match ( '/teams/123/' ) ) . toEqual ( {
321+ teamId : '123' ,
322+ } )
323+ expect ( ( ) => pattern . match ( '/teams/123' ) ) . toThrow ( )
324+ expect ( ( ) => pattern . match ( '/teams/123/b' ) ) . toThrow ( )
325+ expect ( ( ) => pattern . match ( '/teams/' ) ) . toThrow ( )
326+ expect ( pattern . build ( { teamId : '123' } ) ) . toBe ( '/teams/123/' )
327+ } )
328+
329+ it ( 'can have a trailing slash after a static segment' , ( ) => {
330+ const pattern = new MatcherPatternPathDynamic ( / ^ \/ t e a m s \/ b \/ $ / i, { } , [
331+ 'teams' ,
332+ [ 'b' , '/' ] ,
333+ ] )
334+
335+ expect ( pattern . match ( '/teams/b/' ) ) . toEqual ( { } )
336+ expect ( ( ) => pattern . match ( '/teams/b' ) ) . toThrow ( )
337+ expect ( ( ) => pattern . match ( '/teams/123/b' ) ) . toThrow ( )
338+ expect ( ( ) => pattern . match ( '/teams/' ) ) . toThrow ( )
339+ expect ( pattern . build ( { } ) ) . toBe ( '/teams/b/' )
340+ } )
341+
342+ it ( 'can have a trailing slash after repeatable param' , ( ) => {
343+ const pattern = new MatcherPatternPathDynamic (
344+ / ^ \/ t e a m s \/ ( .+ ?) \/ $ / ,
345+ {
346+ teamId : { repeat : true } ,
347+ } ,
348+ [ 'teams' , [ 0 , '/' ] ]
349+ )
350+
351+ expect ( pattern . match ( '/teams/123/' ) ) . toEqual ( { teamId : [ '123' ] } )
352+ expect ( pattern . match ( '/teams/123/456/' ) ) . toEqual ( {
353+ teamId : [ '123' , '456' ] ,
354+ } )
355+ expect ( ( ) => pattern . match ( '/teams/123' ) ) . toThrow ( )
356+ expect ( ( ) => pattern . match ( '/teams/123/b' ) ) . toThrow ( )
357+ expect ( ( ) => pattern . match ( '/teams/' ) ) . toThrow ( )
358+ expect ( pattern . build ( { teamId : [ '123' ] } ) ) . toBe ( '/teams/123/' )
359+ expect ( pattern . build ( { teamId : [ '123' , '456' ] } ) ) . toBe ( '/teams/123/456/' )
360+ } )
361+
362+ it . todo ( 'can have a trailing slash after optional repeatable param' , ( ) => {
363+ const pattern = new MatcherPatternPathDynamic (
364+ / ^ \/ t e a m s (?: \/ ( .+ ?) ) ? \/ $ / ,
365+ {
366+ teamId : { repeat : true } ,
367+ } ,
368+ [ 'teams' , [ 0 , '/' ] ]
369+ )
370+
371+ expect ( pattern . match ( '/teams/123/' ) ) . toEqual ( { teamId : [ '123' ] } )
372+ expect ( pattern . match ( '/teams/123/456/' ) ) . toEqual ( {
373+ teamId : [ '123' , '456' ] ,
374+ } )
375+ expect ( pattern . match ( '/teams/' ) ) . toEqual ( { teamId : [ ] } )
376+
377+ expect ( ( ) => pattern . match ( '/teams/123' ) ) . toThrow ( )
378+ expect ( ( ) => pattern . match ( '/teams/123/b' ) ) . toThrow ( )
379+
380+ expect ( pattern . build ( { teamId : [ '123' ] } ) ) . toBe ( '/teams/123/' )
381+ expect ( pattern . build ( { teamId : [ '123' , '456' ] } ) ) . toBe ( '/teams/123/456/' )
382+ expect ( pattern . build ( { teamId : [ ] } ) ) . toBe ( '/teams/' )
383+ } )
305384} )
0 commit comments