]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: encode fullpath used for links
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 16 Aug 2019 17:21:19 +0000 (19:21 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Fri, 16 Aug 2019 17:21:19 +0000 (19:21 +0200)
__tests__/url-encoding.spec.js

index e93c334b40d68b2ddea5e29f9dc93129eccc5ced..fb687a117e4ee8f0c74fa11bc3b6b99bb08845ec 100644 (file)
@@ -9,7 +9,7 @@ const routes = [
   { path: '/', name: 'home', component: components.Home },
   { path: '/%25', name: 'percent', component: components.Home },
   { path: '/to-p/:p', redirect: to => `/p/${to.params.p}` },
-  { path: '/p/:p', component: components.Bar },
+  { path: '/p/:p', component: components.Bar, name: 'params' },
 ]
 
 function createHistory(initialUrl) {
@@ -42,7 +42,7 @@ describe('URL Encoding', () => {
       await router.doInitialNavigation()
       expect(router.currentRoute).toEqual(
         expect.objectContaining({
-          name: undefined,
+          name: 'params',
           fullPath: encodeURI('/p/€'),
           params: { p: '€' },
           path: encodeURI('/p/€'),
@@ -50,13 +50,28 @@ describe('URL Encoding', () => {
       )
     })
 
+    it('encodes params when resolving', async () => {
+      const history = createHistory('/')
+      const router = new Router({ history, routes })
+      await router.doInitialNavigation()
+      await router.push({ name: 'params', params: { p: '%€' } })
+      expect(router.currentRoute).toEqual(
+        expect.objectContaining({
+          name: 'params',
+          fullPath: encodeURI('/p/%€'),
+          params: { p: '%€' },
+          path: encodeURI('/p/%€'),
+        })
+      )
+    })
+
     it('allows navigating to valid unencoded params (IE and Edge)', async () => {
       const history = createHistory('/p/€')
       const router = new Router({ history, routes })
       await router.doInitialNavigation()
       expect(router.currentRoute).toEqual(
         expect.objectContaining({
-          name: undefined,
+          name: 'params',
           // unfortunately, we cannot encode the path as we cannot know if it already encoded
           // so comparing fullPath and path here is pointless
           // fullPath: '/p/€',
@@ -75,7 +90,7 @@ describe('URL Encoding', () => {
       spy.mockRestore()
       expect(router.currentRoute).toEqual(
         expect.objectContaining({
-          name: undefined,
+          name: 'params',
           // unfortunately, we cannot encode the path as we cannot know if it already encoded
           // so comparing fullPath and path here is pointless
           // fullPath: '/p/€',