From: Eduardo San Martin Morote Date: Tue, 16 Apr 2019 16:40:58 +0000 (+0200) Subject: test: test normalizeLocation X-Git-Tag: v4.0.0-alpha.0~435 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0e3389c60c4032b257c95e3d1b404f4d607634b1;p=thirdparty%2Fvuejs%2Frouter.git test: test normalizeLocation --- diff --git a/__tests__/url.spec.js b/__tests__/url.spec.js index ee0a8764..7f86dad4 100644 --- a/__tests__/url.spec.js +++ b/__tests__/url.spec.js @@ -1,7 +1,11 @@ // @ts-check require('./helper') const expect = require('expect') -const { parseURL, stringifyURL } = require('../src/history/utils') +const { + parseURL, + stringifyURL, + normalizeLocation, +} = require('../src/history/utils') describe('parseURL', () => { it('works with no query no hash', () => { @@ -108,3 +112,32 @@ describe('stringifyURL', () => { ).toBe('/path?foo=a&bar=b#hey') }) }) + +describe('normalizeLocation', () => { + it('works with string', () => { + expect(normalizeLocation('/foo')).toEqual(parseURL('/foo')) + }) + + it('works with objects', () => { + expect( + normalizeLocation({ + path: '/foo', + }) + ).toEqual({ path: '/foo', fullPath: '/foo', query: {}, hash: '' }) + }) + + it('works with objects and keeps query and hash', () => { + expect( + normalizeLocation({ + path: '/foo', + query: { foo: 'a' }, + hash: '#hey', + }) + ).toEqual({ + path: '/foo', + fullPath: '/foo?foo=a#hey', + query: { foo: 'a' }, + hash: '#hey', + }) + }) +})