forked from vuejs/test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderToString.ts
31 lines (28 loc) · 1.03 KB
/
renderToString.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { renderToString as baseRenderToString } from '@vue/server-renderer'
import { DefineComponent } from 'vue'
import { createInstance } from './createInstance'
import { ComponentMountingOptions } from './mount'
import { RenderMountingOptions } from './types'
export function renderToString<
T,
C = T extends ((...args: any) => any) | (new (...args: any) => any)
? T
: T extends { props?: infer Props }
? DefineComponent<
Props extends Readonly<(infer PropNames)[]> | (infer PropNames)[]
? { [key in PropNames extends string ? PropNames : string]?: any }
: Props
>
: DefineComponent
>(
originalComponent: T,
options?: ComponentMountingOptions<C> &
Pick<RenderMountingOptions<any>, 'attachTo'>
): Promise<string>
export function renderToString(component: any, options?: any): Promise<string> {
if (options?.attachTo) {
console.warn('attachTo option is not available for renderToString')
}
const { app } = createInstance(component, options)
return baseRenderToString(app)
}