From: Eduardo San Martin Morote Date: Tue, 16 Apr 2019 16:32:38 +0000 (+0200) Subject: test: add strigifyURL tests X-Git-Tag: v4.0.0-alpha.0~437 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f3a9f2f21e88e6c1c9ae1e66f433775b687b409;p=thirdparty%2Fvuejs%2Frouter.git test: add strigifyURL tests --- diff --git a/__tests__/url.spec.js b/__tests__/url.spec.js index 60bf3bd7..ee0a8764 100644 --- a/__tests__/url.spec.js +++ b/__tests__/url.spec.js @@ -1,9 +1,9 @@ // @ts-check require('./helper') const expect = require('expect') -const { parseURL } = require('../src/history/utils') +const { parseURL, stringifyURL } = require('../src/history/utils') -describe('URL parsing', () => { +describe('parseURL', () => { it('works with no query no hash', () => { expect(parseURL('/foo')).toEqual({ fullPath: '/foo', @@ -52,3 +52,59 @@ describe('URL parsing', () => { }) }) }) + +describe('stringifyURL', () => { + it('stringifies a path', () => { + expect( + stringifyURL({ + path: '/some-path', + }) + ).toBe('/some-path') + }) + + it('stringifies a query with arrays', () => { + expect( + stringifyURL({ + path: '/path', + query: { + foo: ['a1', 'a2'], + bar: 'b', + }, + }) + ).toBe('/path?foo=a1&foo=a2&bar=b') + }) + + it('stringifies a query', () => { + expect( + stringifyURL({ + path: '/path', + query: { + foo: 'a', + bar: 'b', + }, + }) + ).toBe('/path?foo=a&bar=b') + }) + + it('stringifies a hash', () => { + expect( + stringifyURL({ + path: '/path', + hash: '#hey', + }) + ).toBe('/path#hey') + }) + + it('stringifies a query and a hash', () => { + expect( + stringifyURL({ + path: '/path', + query: { + foo: 'a', + bar: 'b', + }, + hash: '#hey', + }) + ).toBe('/path?foo=a&bar=b#hey') + }) +}) diff --git a/jest.config.js b/jest.config.js index adcdbe78..70c55441 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,6 @@ module.exports = { preset: 'ts-jest', + collectCoverageFrom: ['src/**/*.ts'], testMatch: [ '**/__tests__/**/*.spec.[j]s?(x)', // '**/__tests__/**/*.spec.[jt]s?(x)', diff --git a/src/utils/index.ts b/src/utils/index.ts deleted file mode 100644 index 7da1385c..00000000 --- a/src/utils/index.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { RouteQuery } from '../types' - -// TODO: merge with existing function from history/base.ts and more to -// history utils -export function stringifyQuery(query: RouteQuery | void): string { - if (!query) return '' - - let search = '?' - for (const key in query) { - // TODO: handle arrays - search += `${key}=${query[key]}` - } - - // no query means empty string - return search === '?' ? '' : '' -}