Skip to content

Commit

Permalink
test: removes optional params when specified as null
Browse files Browse the repository at this point in the history
Close #1893
  • Loading branch information
posva committed Jun 20, 2023
1 parent 957c6e7 commit e6dfcde
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions packages/router/__tests__/router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,19 +314,23 @@ describe('Router', () => {
expect(route2.path).toBe('/optional')
expect(route2.params).toEqual({})

// but keeps empty strings
const route3 = router.resolve({
name: 'optional',
params: { p: '' },
})
expect(route3.path).toBe('/optional')
expect(route3.params).toEqual({ p: '' })

await router.push({ name: 'optional', params: { p: null } })
expect(router.currentRoute.value.params).toEqual({})
await router.push({ name: 'optional', params: {} })
})

it('removes null/undefined params when current location has it', async () => {
const { router } = await newRouter()

await router.push({ name: 'optional', params: { p: 'a' } })
await router.push({ name: 'optional', params: { p: null } })
expect(router.currentRoute.value.params).toEqual({})

await router.push({ name: 'optional', params: { p: 'a' } })
await router.push({ name: 'optional', params: { p: undefined } })
expect(router.currentRoute.value.params).toEqual({})
})

it('keeps empty strings', async () => {
const { router } = await newRouter()
const route1 = router.resolve({ name: 'optional', params: { p: '' } })
Expand Down

0 comments on commit e6dfcde

Please sign in to comment.