Skip to content

Commit e6dfcde

Browse files
committed
test: removes optional params when specified as null
Close #1893
1 parent 957c6e7 commit e6dfcde

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

packages/router/__tests__/router.spec.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -314,19 +314,23 @@ describe('Router', () => {
314314
expect(route2.path).toBe('/optional')
315315
expect(route2.params).toEqual({})
316316

317-
// but keeps empty strings
318-
const route3 = router.resolve({
319-
name: 'optional',
320-
params: { p: '' },
321-
})
322-
expect(route3.path).toBe('/optional')
323-
expect(route3.params).toEqual({ p: '' })
324-
325317
await router.push({ name: 'optional', params: { p: null } })
326318
expect(router.currentRoute.value.params).toEqual({})
327319
await router.push({ name: 'optional', params: {} })
328320
})
329321

322+
it('removes null/undefined params when current location has it', async () => {
323+
const { router } = await newRouter()
324+
325+
await router.push({ name: 'optional', params: { p: 'a' } })
326+
await router.push({ name: 'optional', params: { p: null } })
327+
expect(router.currentRoute.value.params).toEqual({})
328+
329+
await router.push({ name: 'optional', params: { p: 'a' } })
330+
await router.push({ name: 'optional', params: { p: undefined } })
331+
expect(router.currentRoute.value.params).toEqual({})
332+
})
333+
330334
it('keeps empty strings', async () => {
331335
const { router } = await newRouter()
332336
const route1 = router.resolve({ name: 'optional', params: { p: '' } })

0 commit comments

Comments
 (0)