]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: removes optional params when specified as null
authorEduardo San Martin Morote <posva13@gmail.com>
Tue, 20 Jun 2023 14:45:41 +0000 (16:45 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Tue, 20 Jun 2023 14:45:41 +0000 (16:45 +0200)
Close #1893

packages/router/__tests__/router.spec.ts

index 03766994bf871e798091d70509c9e1e38e2e1950..235002f24c95773c64257a96eb16346bb526b545 100644 (file)
@@ -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: '' } })