]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: add strigifyURL tests
authorEduardo San Martin Morote <posva13@gmail.com>
Tue, 16 Apr 2019 16:32:38 +0000 (18:32 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Tue, 16 Apr 2019 16:32:38 +0000 (18:32 +0200)
__tests__/url.spec.js
jest.config.js
src/utils/index.ts [deleted file]

index 60bf3bd788d3ba9eab70a171ac81345a3da49e57..ee0a8764afebb3050bad2bee746c6878a5fbd707 100644 (file)
@@ -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')
+  })
+})
index adcdbe787174066b81cfaa2155bf9c8f74e590dd..70c55441f0e2eb5fc363019bca44133b1d2366bc 100644 (file)
@@ -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 (file)
index 7da1385..0000000
+++ /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 === '?' ? '' : ''
-}