]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix: initial location with base
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 19 Mar 2020 16:41:06 +0000 (17:41 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 19 Mar 2020 16:41:06 +0000 (17:41 +0100)
__tests__/history/locationUtils.spec.ts [new file with mode: 0644]
e2e/specs/encoding.js
src/history/common.ts

diff --git a/__tests__/history/locationUtils.spec.ts b/__tests__/history/locationUtils.spec.ts
new file mode 100644 (file)
index 0000000..35bf0b1
--- /dev/null
@@ -0,0 +1,22 @@
+import { stripBase } from '../../src/history/common'
+import { createDom } from '../utils'
+
+describe('History Location Utils', () => {
+  beforeAll(() => {
+    createDom()
+  })
+
+  describe('stripBase', () => {
+    it('returns the pathname if no base', () => {
+      expect(stripBase('', '')).toBe('')
+      expect(stripBase('/', '')).toBe('/')
+      expect(stripBase('/thing', '')).toBe('/thing')
+    })
+
+    it('returns the pathname without the base', () => {
+      expect(stripBase('/base', '/base')).toBe('/')
+      expect(stripBase('/base/', '/base')).toBe('/')
+      expect(stripBase('/base/foo', '/base')).toBe('/foo')
+    })
+  })
+})
index 305f501557524d0ff0f0e5b3eff8723345251b7e..c11bef6a94c449aebf5eac9068b2f9640eb7ffb6 100644 (file)
@@ -11,6 +11,8 @@ module.exports = {
   basic(browser) {
     browser
       .url(baseURL)
+      // TODO: move this test to a different spec
+      .assert.urlEquals(baseURL + '/')
       .waitForElementVisible('#app', 1000)
 
       .click('li:nth-child(3) a')
@@ -20,18 +22,12 @@ module.exports = {
       .assert.containsText('#params', JSON.stringify({ id: '€uro' }, null, 2))
 
       // check initial visit
-      .url(baseURL + '/encoding/documents/%E2%82%ACuro')
+      .url(baseURL + '/documents/%E2%82%ACuro')
       .waitForElementVisible('#app', 1000)
       .assert.containsText('#fullPath', '/documents/%E2%82%ACuro')
       .assert.containsText('#path', '/documents/%E2%82%ACuro')
-    // .assert.containsText('#params', JSON.stringify({ id: '€uro' }, null, 2))
-    // .assert.containsText('#params', JSON.stringify({ id: '€uro' }, null, 2))
+      .assert.containsText('#params', JSON.stringify({ id: '€uro' }, null, 2))
 
-    browser
-      .getText('#params', function(res) {
-        this.assert.equal(res.value, JSON.stringify({ id: '€uro' }, null, 2))
-        console.log(res.state)
-      })
       .end()
   },
 }
index f8eab7f01aad14260b823a5cc654782eddf5a9fa..41efecb1b7f07e8802db6f406b88941bd4bd82e5 100644 (file)
@@ -152,10 +152,8 @@ export function stringifyURL(
  * @param base base to strip off
  */
 export function stripBase(pathname: string, base: string): string {
-  return (
-    (base && pathname.indexOf(base) === 0 && pathname.replace(base, '')) ||
-    pathname
-  )
+  if (!base || pathname.indexOf(base) !== 0) return pathname
+  return pathname.replace(base, '') || '/'
 }
 
 export function normalizeHistoryLocation(