@@ -9,26 +9,68 @@ import {
99 ssrRenderComponent ,
1010} from '@vue/server-renderer'
1111
12+ const delay = ( t : number ) => new Promise ( resolve => setTimeout ( resolve , t ) )
13+
1214describe ( 'SSR' , ( ) => {
15+ const Home = {
16+ ssrRender ( ctx : any , push : any ) {
17+ push ( 'Home' )
18+ } ,
19+ }
20+ const Page = {
21+ ssrRender ( ctx : any , push : any ) {
22+ push ( `${ ssrInterpolate ( ctx . $route . fullPath ) } ` )
23+ } ,
24+ }
25+
26+ const AsyncPage = async ( ) => {
27+ await delay ( 10 )
28+ return Page
29+ }
30+
1331 it ( 'works' , async ( ) => {
14- const Home = {
15- ssrRender ( ctx : any , push : any ) {
16- push ( 'Home' )
17- } ,
18- }
19- const Page = {
20- ssrRender ( ctx : any , push : any ) {
21- push ( `${ ssrInterpolate ( ctx . $route . fullPath ) } ` )
32+ const router = createRouter ( {
33+ history : createMemoryHistory ( ) ,
34+ routes : [
35+ { path : '/' , component : Home } ,
36+ {
37+ path : '/:id' ,
38+ component : Page ,
39+ } ,
40+ ] ,
41+ } )
42+ const App = {
43+ ssrRender ( ctx : any , push : any , parent : any ) {
44+ push (
45+ ssrRenderComponent (
46+ resolveComponent ( 'router-view' ) as Component ,
47+ null ,
48+ null ,
49+ parent
50+ )
51+ )
2252 } ,
2353 }
54+ const app = createSSRApp ( App )
55+ app . use ( router )
56+ // const rootEl = document.createElement('div')
57+ // document.body.appendChild(rootEl)
2458
59+ router . push ( '/hello' )
60+ await router . isReady ( )
61+
62+ const xxx = await renderToString ( app )
63+ expect ( xxx ) . toMatchInlineSnapshot ( `"/hello"` )
64+ } )
65+
66+ it ( 'handles async components' , async ( ) => {
2567 const router = createRouter ( {
2668 history : createMemoryHistory ( ) ,
2769 routes : [
2870 { path : '/' , component : Home } ,
2971 {
3072 path : '/:id' ,
31- component : Page ,
73+ component : AsyncPage ,
3274 } ,
3375 ] ,
3476 } )
0 commit comments