]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: move history tests to own folder
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 28 Jun 2019 09:26:20 +0000 (11:26 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Fri, 28 Jun 2019 09:26:20 +0000 (11:26 +0200)
__tests__/history/abstract.spec.js [moved from __tests__/abstract.spec.js with 96% similarity]
__tests__/history/html5.spec.js [moved from __tests__/html5.spec.js with 57% similarity]
__tests__/router.spec.js

similarity index 96%
rename from __tests__/abstract.spec.js
rename to __tests__/history/abstract.spec.js
index 6e38c12f5b8f50a9c732f6251623adca5eb0a463..b32fb881fe81ed591fe12a249584fe69e55d51ca 100644 (file)
@@ -1,11 +1,11 @@
 // @ts-check
 
-require('./helper')
+require('../helper')
 const expect = require('expect')
-const { AbstractHistory } = require('../src/history/abstract')
-const { START } = require('../src/history/base')
+const { AbstractHistory } = require('../../src/history/abstract')
+const { START } = require('../../src/history/base')
 
-/** @type {import('../src/history/base').HistoryLocation} */
+/** @type {import('../../src/history/base').HistoryLocation} */
 const loc = {
   path: '/foo',
 }
similarity index 57%
rename from __tests__/html5.spec.js
rename to __tests__/history/html5.spec.js
index 7a714011e5e537351fd7fc4f5365250105d8e92f..ccc0b4d6f6c6ab280ffb2b66d7dfcc3fa77ee4a5 100644 (file)
@@ -1,9 +1,11 @@
 // @ts-check
-require('./helper')
+require('../helper')
 const expect = require('expect')
-const { HTML5History } = require('../src/history/html5')
-const { createDom } = require('./utils')
+const { HTML5History } = require('../../src/history/html5')
+const { createDom } = require('../utils')
 
+// TODO: is it really worth testing this implementation on jest or is it
+// better to directly use e2e tests instead
 describe.skip('History HTMl5', () => {
   beforeAll(() => {
     createDom()
index 02832445ea4e3b5a82e6062862267377bb5f8e87..a748511b1c5294ce07abd7f980e02b6b21a3cf28 100644 (file)
@@ -8,7 +8,13 @@ const { Router } = require('../src/router')
 const { NavigationCancelled } = require('../src/errors')
 const { createDom, components, tick } = require('./utils')
 
-function mockHistory() {
+/**
+ * Created a mocked version of the history
+ * @param {string} [start] starting locationh
+ */
+function mockHistory(start) {
+  // @ts-ignore
+  if (start) window.location = start
   // TODO: actually do a mock
   return new HTML5History()
 }
@@ -16,6 +22,7 @@ function mockHistory() {
 /** @type {import('../src/types').RouteRecord[]} */
 const routes = [
   { path: '/', component: components.Home },
+  { path: '/search', component: components.Home },
   { path: '/foo', component: components.Foo, name: 'Foo' },
   { path: '/to-foo', redirect: '/foo' },
   { path: '/to-foo-named', redirect: { name: 'Foo' } },
@@ -49,6 +56,19 @@ describe('Router', () => {
     })
   })
 
+  // TODO: should do other checks not based on history implem
+  it.skip('takes browser location', () => {
+    const history = mockHistory('/search?q=dog#footer')
+    const router = new Router({ history, routes })
+    expect(router.currentRoute).toEqual({
+      fullPath: '/search?q=dog#footer',
+      hash: '#footer',
+      params: {},
+      path: '/search',
+      query: { q: 'dog' },
+    })
+  })
+
   it('calls history.push with router.push', async () => {
     const history = mockHistory()
     const router = new Router({ history, routes })
@@ -77,6 +97,20 @@ describe('Router', () => {
     })
   })
 
+  it('can pass replace option to push', async () => {
+    const history = mockHistory()
+    const router = new Router({ history, routes })
+    jest.spyOn(history, 'replace')
+    await router.push({ path: '/foo', replace: true })
+    expect(history.replace).toHaveBeenCalledTimes(1)
+    expect(history.replace).toHaveBeenCalledWith({
+      fullPath: '/foo',
+      path: '/foo',
+      query: {},
+      hash: '',
+    })
+  })
+
   describe('navigation', () => {
     async function checkNavigationCancelledOnPush(target) {
       const [p1, r1] = fakePromise()
@@ -170,7 +204,7 @@ describe('Router', () => {
     })
 
     it('cancels navigation abort if a newer one is finished on user navigation (from history)', async () => {
-      await checkNavigationCancelledOnPush(undefined, '/p/b')
+      await checkNavigationCancelledOnPush(undefined)
     })
   })