From e6dfcde1598fc95a2ec83df2d4bae9477a73867f Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Tue, 20 Jun 2023 16:45:41 +0200 Subject: [PATCH] test: removes optional params when specified as null Close #1893 --- packages/router/__tests__/router.spec.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/router/__tests__/router.spec.ts b/packages/router/__tests__/router.spec.ts index 03766994b..235002f24 100644 --- a/packages/router/__tests__/router.spec.ts +++ b/packages/router/__tests__/router.spec.ts @@ -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: '' } })