From: Eduardo San Martin Morote Date: Fri, 3 Apr 2020 11:53:22 +0000 (+0200) Subject: refactor: typos and refactor in tests X-Git-Tag: v4.0.0-alpha.5~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0fbfdfc6518cfdb89ca77ab257190984b2331dc2;p=thirdparty%2Fvuejs%2Frouter.git refactor: typos and refactor in tests --- diff --git a/__tests__/errors.spec.ts b/__tests__/errors.spec.ts index 1bfea05f..92e115b2 100644 --- a/__tests__/errors.spec.ts +++ b/__tests__/errors.spec.ts @@ -54,7 +54,7 @@ describe('Errors', () => { ) }) - it('triggers erros caused by new navigations of a next(redirect) trigered by history', async () => { + it('triggers errors caused by new navigations of a next(redirect) triggered by history', async () => { const { router, history } = createRouter() await router.push('/p/0') await router.push('/p/other') diff --git a/__tests__/guards/component-beforeRouteEnter.spec.ts b/__tests__/guards/component-beforeRouteEnter.spec.ts index f9002fe6..9513c3ac 100644 --- a/__tests__/guards/component-beforeRouteEnter.spec.ts +++ b/__tests__/guards/component-beforeRouteEnter.spec.ts @@ -1,17 +1,6 @@ -import { RouterOptions, createRouter as newRouter } from '../../src/router' import fakePromise from 'faked-promise' -import { createDom, noGuard } from '../utils' +import { createDom, noGuard, newRouter as createRouter } from '../utils' import { RouteRecordRaw, NavigationGuard } from '../../src/types' -import { createWebHistory } from '../../src' - -function createRouter( - options: Partial & { routes: RouteRecordRaw[] } -) { - return newRouter({ - history: createWebHistory(), - ...options, - }) -} const Home = { template: `
Home
` } const Foo = { template: `
Foo
` } diff --git a/__tests__/guards/component-beforeRouteLeave.spec.ts b/__tests__/guards/component-beforeRouteLeave.spec.ts index be1e3ea2..7e22e727 100644 --- a/__tests__/guards/component-beforeRouteLeave.spec.ts +++ b/__tests__/guards/component-beforeRouteLeave.spec.ts @@ -1,17 +1,5 @@ -import { RouterOptions, createRouter as newRouter } from '../../src/router' -import { createDom, noGuard } from '../utils' +import { createDom, noGuard, newRouter as createRouter } from '../utils' import { RouteRecordRaw } from '../../src/types' -import { createWebHistory } from '../../src' - -// TODO: refactor in utils -function createRouter( - options: Partial & { routes: RouteRecordRaw[] } -) { - return newRouter({ - history: createWebHistory(), - ...options, - }) -} const Home = { template: `
Home
` } const Foo = { template: `
Foo
` } diff --git a/__tests__/guards/component-beforeRouteUpdate.spec.ts b/__tests__/guards/component-beforeRouteUpdate.spec.ts index 517d70fe..4c6a724a 100644 --- a/__tests__/guards/component-beforeRouteUpdate.spec.ts +++ b/__tests__/guards/component-beforeRouteUpdate.spec.ts @@ -1,19 +1,7 @@ import fakePromise from 'faked-promise' -import { createDom, noGuard } from '../utils' -import { createRouter as newRouter, createWebHistory } from '../../src' +import { createDom, noGuard, newRouter as createRouter } from '../utils' import { RouteRecordRaw } from '../../src/types' -function createRouter( - options: Partial & { - routes: import('../../src/types').RouteRecordRaw[] - } -) { - return newRouter({ - history: createWebHistory(), - ...options, - }) -} - const Home = { template: `
Home
` } const Foo = { template: `
Foo
` } diff --git a/__tests__/guards/global-after.spec.ts b/__tests__/guards/global-after.spec.ts index f2b96db1..ae458c07 100644 --- a/__tests__/guards/global-after.spec.ts +++ b/__tests__/guards/global-after.spec.ts @@ -1,18 +1,6 @@ -import { createDom } from '../utils' -import { createWebHistory, createRouter as newRouter } from '../../src' +import { createDom, newRouter as createRouter } from '../utils' import { RouteRecordRaw } from 'src/types' -function createRouter( - options: Partial & { - routes: import('../../src/types').RouteRecordRaw[] - } -) { - return newRouter({ - history: createWebHistory(), - ...options, - }) -} - const Home = { template: `
Home
` } const Foo = { template: `
Foo
` } const Nested = { template: `
Nested
` } diff --git a/__tests__/guards/global-beforeEach.spec.ts b/__tests__/guards/global-beforeEach.spec.ts index 797333cb..4cc45e08 100644 --- a/__tests__/guards/global-beforeEach.spec.ts +++ b/__tests__/guards/global-beforeEach.spec.ts @@ -1,17 +1,6 @@ -import { RouterOptions } from '../../src/router' import fakePromise from 'faked-promise' -import { createDom, tick, noGuard } from '../utils' +import { createDom, tick, noGuard, newRouter as createRouter } from '../utils' import { RouteRecordRaw, RouteLocationRaw } from '../../src/types' -import { createWebHistory, createRouter as newRouter } from '../../src' - -function createRouter( - options: Partial & { routes: RouteRecordRaw[] } -) { - return newRouter({ - history: createWebHistory(), - ...options, - }) -} const Home = { template: `
Home
` } const Foo = { template: `
Foo
` } diff --git a/__tests__/guards/route-beforeEnter.spec.ts b/__tests__/guards/route-beforeEnter.spec.ts index 825549d0..913b0d04 100644 --- a/__tests__/guards/route-beforeEnter.spec.ts +++ b/__tests__/guards/route-beforeEnter.spec.ts @@ -1,17 +1,6 @@ -import { RouterOptions, createRouter as newRouter } from '../../src/router' import fakePromise from 'faked-promise' -import { createDom, noGuard, tick } from '../utils' +import { createDom, noGuard, tick, newRouter as createRouter } from '../utils' import { RouteRecordRaw } from '../../src/types' -import { createWebHistory } from '../../src' - -function createRouter( - options: Partial & { routes: RouteRecordRaw[] } -) { - return newRouter({ - history: createWebHistory(), - ...options, - }) -} const Home = { template: `
Home
` } const Foo = { template: `
Foo
` } diff --git a/__tests__/history/memory.spec.ts b/__tests__/history/memory.spec.ts index 72aaf23a..aee86f58 100644 --- a/__tests__/history/memory.spec.ts +++ b/__tests__/history/memory.spec.ts @@ -115,7 +115,6 @@ describe('Memory history', () => { expect(spy).toHaveBeenCalledWith(START, normaliezedLoc, { direction: 'back', distance: -1, - // TODO: should be something else type: 'pop', }) history.forward() @@ -123,7 +122,6 @@ describe('Memory history', () => { expect(spy).toHaveBeenLastCalledWith(normaliezedLoc, START, { direction: 'forward', distance: 1, - // TODO: should be something else type: 'pop', }) }) diff --git a/__tests__/matcher/path-parser.spec.ts b/__tests__/matcher/path-parser.spec.ts index 1e314e3e..446d274d 100644 --- a/__tests__/matcher/path-parser.spec.ts +++ b/__tests__/matcher/path-parser.spec.ts @@ -621,6 +621,12 @@ describe('Path parser', () => { matchParams('/a/:a(?:b-([^/]+\\)?)', '/a/b-one', { a: 'one', }) + matchParams('/a/:a(?:b-([^/]+\\)?)', '/a/b-', { + a: '', + }) + matchParams('/a/:a(?:b-([^/]+\\))', '/a/b-one', { + a: 'one', + }) }) it('catch all', () => { diff --git a/__tests__/matcher/records.spec.ts b/__tests__/matcher/records.spec.ts index 1446565c..afb168c3 100644 --- a/__tests__/matcher/records.spec.ts +++ b/__tests__/matcher/records.spec.ts @@ -83,11 +83,4 @@ describe('normalizeRouteRecord', () => { props: false, }) }) - - // TODO: move to router - it.todo('beforeEnter is called with the string redirect') - - it.todo('beforeEnter is called with object redirect') - - it.todo('function redirect is invoked by beforeEnter') }) diff --git a/__tests__/utils.ts b/__tests__/utils.ts index 04167bcf..09ab8151 100644 --- a/__tests__/utils.ts +++ b/__tests__/utils.ts @@ -6,8 +6,10 @@ import { RouteLocationNormalized, _RouteRecordBase, RouteComponent, + RouteRecordRaw, } from '../src/types' import { h, resolveComponent, ComponentOptions } from 'vue' +import { RouterOptions, createWebHistory, createRouter } from '../src' export const tick = (time?: number) => new Promise(resolve => { @@ -132,3 +134,12 @@ export const components = { }, } as RouteComponent, } + +export function newRouter( + options: Partial & { routes: RouteRecordRaw[] } +) { + return createRouter({ + history: options.history || createWebHistory(), + ...options, + }) +}