From: Eduardo San Martin Morote Date: Fri, 16 Aug 2019 17:37:53 +0000 (+0200) Subject: test: add but skip hash test X-Git-Tag: v4.0.0-alpha.0~262 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5cf45cddca38e269d0f0df736bd89cbe2f9cdc4;p=thirdparty%2Fvuejs%2Frouter.git test: add but skip hash test --- diff --git a/__tests__/url-encoding.spec.js b/__tests__/url-encoding.spec.js index fb687a11..f97b767e 100644 --- a/__tests__/url-encoding.spec.js +++ b/__tests__/url-encoding.spec.js @@ -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/%€'), + }) + ) + }) }) })