From: Eduardo San Martin Morote Date: Fri, 16 Aug 2019 17:21:19 +0000 (+0200) Subject: test: encode fullpath used for links X-Git-Tag: v4.0.0-alpha.0~264 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bdb31162c0212352b1fe8beba6d263b844a6bda4;p=thirdparty%2Fvuejs%2Frouter.git test: encode fullpath used for links --- diff --git a/__tests__/url-encoding.spec.js b/__tests__/url-encoding.spec.js index e93c334b..fb687a11 100644 --- a/__tests__/url-encoding.spec.js +++ b/__tests__/url-encoding.spec.js @@ -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/€',