]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: test normalizeLocation
authorEduardo San Martin Morote <posva13@gmail.com>
Tue, 16 Apr 2019 16:40:58 +0000 (18:40 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Tue, 16 Apr 2019 16:40:58 +0000 (18:40 +0200)
__tests__/url.spec.js

index ee0a8764afebb3050bad2bee746c6878a5fbd707..7f86dad40bea280deb74655afa3f0aff1e8c26c4 100644 (file)
@@ -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',
+    })
+  })
+})