From 0e3389c60c4032b257c95e3d1b404f4d607634b1 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Tue, 16 Apr 2019 18:40:58 +0200 Subject: [PATCH] test: test normalizeLocation --- __tests__/url.spec.js | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) 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', + }) + }) +}) -- 2.47.2