]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: add but skip hash test
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 16 Aug 2019 17:37:53 +0000 (19:37 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Fri, 16 Aug 2019 17:37:53 +0000 (19:37 +0200)
__tests__/url-encoding.spec.js

index fb687a117e4ee8f0c74fa11bc3b6b99bb08845ec..f97b767e413b33d6b569fe98ade82bfa0a7d3df4 100644 (file)
@@ -50,21 +50,6 @@ 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 })
@@ -134,5 +119,58 @@ describe('URL Encoding', () => {
         })
       )
     })
+
+    // TODO: we don't do this in current version of vue-router
+    // should we do it? it seems to be a bit different as it allows using % without
+    // encoding it. To be safe we would have to encode everything
+    it.skip('decodes hash', async () => {
+      const history = createHistory('/#%25%E2%82%AC')
+      const router = new Router({ history, routes })
+      await router.doInitialNavigation()
+      expect(router.currentRoute).toEqual(
+        expect.objectContaining({
+          name: 'home',
+          fullPath: '/#' + encodeURIComponent('%€'),
+          hash: '#%€',
+          path: '/',
+        })
+      )
+    })
+
+    it('allow unencoded params in query (IE Edge)', async () => {
+      const spy = jest.spyOn(console, 'warn').mockImplementation(() => {})
+      const history = createHistory('/?q=€%notvalid')
+      const router = new Router({ history, routes })
+      await router.doInitialNavigation()
+      expect(spy).toHaveBeenCalledTimes(1)
+      spy.mockRestore()
+      expect(router.currentRoute).toEqual(
+        expect.objectContaining({
+          name: 'home',
+          fullPath: '/?q=' + encodeURIComponent('€%notvalid'),
+          query: {
+            q: '€%notvalid',
+          },
+          path: '/',
+        })
+      )
+    })
+  })
+
+  describe('resolving locations', () => {
+    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/%€'),
+        })
+      )
+    })
   })
 })