Skip to content

Commit

Permalink
param types is optional now.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterp committed Mar 21, 2020
1 parent 9b72f13 commit 4ab718d
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions packages/router/src/__tests__/util.test.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
import { matchPath } from '../util'

const coreParamTypes = {
Int: {
constraint: /\d+/,
transform: Number,
},
}

describe('matchPath', () => {
it('matches paths correctly', () => {
expect(matchPath('/post/{id:Int}', '/post/7', coreParamTypes)).toEqual({
expect(matchPath('/post/{id:Int}', '/post/7')).toEqual({
match: true,
params: { id: 7 },
})

expect(
matchPath(
'/blog/{year}/{month}/{day}',
'/blog/2019/12/07',
coreParamTypes
)
matchPath('/blog/{year}/{month}/{day}', '/blog/2019/12/07')
).toEqual({ match: true, params: { day: '07', month: '12', year: '2019' } })

expect(matchPath('/about', '/', coreParamTypes)).toEqual({ match: false })
expect(matchPath('/about', '/')).toEqual({ match: false })
})

it('transforms a param based on the specified transform', () => {
expect(matchPath('/post/{id:Int}', '/post/1337', coreParamTypes)).toEqual({
expect(matchPath('/post/{id:Int}', '/post/1337')).toEqual({
match: true,
params: { id: 1337 },
})
Expand Down

0 comments on commit 4ab718d

Please sign in to comment.