From: Eduardo San Martin Morote Date: Thu, 9 Apr 2020 18:50:52 +0000 (+0200) Subject: test: remove old mount helper X-Git-Tag: v4.0.0-alpha.6~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=575d0c9b498d947ba10c8e29a8b88c85161afb89;p=thirdparty%2Fvuejs%2Frouter.git test: remove old mount helper --- diff --git a/__tests__/mount.ts b/__tests__/mount.ts deleted file mode 100644 index 881ad8d2..00000000 --- a/__tests__/mount.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { - Component, - createApp, - nextTick, - ComputedRef, - reactive, - computed, -} from 'vue' -import * as runtimeDom from '@vue/runtime-dom' -import { compile } from '@vue/compiler-dom' -import { Router, RouteLocationNormalizedLoaded } from '../src' -import { routerKey, routeLocationKey } from '../src/utils/injectionSymbols' - -export function mount( - router: Router, - Component: Component & { - template: string - components?: Record - }, - rootProps = {} -) { - const { template, components, ...ComponentWithoutTemplate } = Component - - const app = createApp(ComponentWithoutTemplate as any, rootProps) - - const reactiveRoute = {} as { - [k in keyof RouteLocationNormalizedLoaded]: ComputedRef< - RouteLocationNormalizedLoaded[k] - > - } - for (let key in router.currentRoute.value) { - // @ts-ignore: the key matches - reactiveRoute[key] = computed(() => router.currentRoute.value[key]) - } - - app.provide(routerKey, router) - app.provide(routeLocationKey, reactive(reactiveRoute)) - - for (const componentName in components) { - app.component(componentName, components[componentName]) - } - - const rootEl = document.createElement('div') - document.body.appendChild(rootEl) - - const codegen = compile(template, { - mode: 'function', - hoistStatic: true, - prefixIdentifiers: true, - }) - - const render = new Function('Vue', codegen.code)(runtimeDom) - - // @ts-ignore - ComponentWithoutTemplate.render = render - - app.mount(rootEl) - - return { app, el: rootEl } -} - -export const tick = () => - new Promise(resolve => { - nextTick(resolve) - })