From: Eduardo San Martin Morote Date: Sun, 27 Sep 2020 11:37:24 +0000 (+0200) Subject: test(ssr): test async components X-Git-Tag: v4.0.0-beta.13~22 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=65c18dbd44b890a51b2dda615929a7c68d699cf1;p=thirdparty%2Fvuejs%2Frouter.git test(ssr): test async components --- diff --git a/__tests__/ssr.spec.ts b/__tests__/ssr.spec.ts index d4b9f243..660c1ae0 100644 --- a/__tests__/ssr.spec.ts +++ b/__tests__/ssr.spec.ts @@ -9,26 +9,68 @@ import { ssrRenderComponent, } from '@vue/server-renderer' +const delay = (t: number) => new Promise(resolve => setTimeout(resolve, t)) + describe('SSR', () => { + const Home = { + ssrRender(ctx: any, push: any) { + push('Home') + }, + } + const Page = { + ssrRender(ctx: any, push: any) { + push(`${ssrInterpolate(ctx.$route.fullPath)}`) + }, + } + + const AsyncPage = async () => { + await delay(10) + return Page + } + it('works', async () => { - const Home = { - ssrRender(ctx: any, push: any) { - push('Home') - }, - } - const Page = { - ssrRender(ctx: any, push: any) { - push(`${ssrInterpolate(ctx.$route.fullPath)}`) + const router = createRouter({ + history: createMemoryHistory(), + routes: [ + { path: '/', component: Home }, + { + path: '/:id', + component: Page, + }, + ], + }) + const App = { + ssrRender(ctx: any, push: any, parent: any) { + push( + ssrRenderComponent( + resolveComponent('router-view') as Component, + null, + null, + parent + ) + ) }, } + const app = createSSRApp(App) + app.use(router) + // const rootEl = document.createElement('div') + // document.body.appendChild(rootEl) + router.push('/hello') + await router.isReady() + + const xxx = await renderToString(app) + expect(xxx).toMatchInlineSnapshot(`"/hello"`) + }) + + it('handles async components', async () => { const router = createRouter({ history: createMemoryHistory(), routes: [ { path: '/', component: Home }, { path: '/:id', - component: Page, + component: AsyncPage, }, ], })