test: add test case

This commit is contained in:
daiwei 2024-12-10 09:02:28 +08:00
parent 637409af75
commit 21454ce627
3 changed files with 37 additions and 3 deletions

View File

@ -66,6 +66,38 @@ describe('ssr: directives', () => {
),
).toBe(`<div style="color:red;font-size:12;display:none;"></div>`)
})
test('with component', async () => {
expect(
await renderToString(
createApp({
components: {
Foo: {
template: `<div><span v-bind="$attrs"></span></div>`,
},
},
data: () => ({ show: false }),
template: `<Foo v-show="show"/>`,
}),
),
).toBe(`<div style="display:none;"><span></span></div>`)
})
test('with dynamic component', async () => {
expect(
await renderToString(
createApp({
components: {
Foo: {
template: `<div><span v-bind="$attrs"></span></div>`,
},
},
data: () => ({ show: false }),
template: `<component is="Foo" v-show="show"/>`,
}),
),
).toBe(`<div style="display:none;"><span></span></div>`)
})
})
describe('template v-model', () => {

View File

@ -13,10 +13,12 @@ export function ssrRenderComponent(
children: Slots | SSRSlots | null = null,
parentComponent: ComponentInternalInstance | null = null,
slotScopeId?: string,
vShowValue?: Props,
): SSRBuffer | Promise<SSRBuffer> {
return renderComponentVNode(
createVNode(comp, props, children),
parentComponent,
slotScopeId,
vShowValue,
)
}

View File

@ -92,7 +92,7 @@ export function renderComponentVNode(
vnode: VNode,
parentComponent: ComponentInternalInstance | null = null,
slotScopeId?: string,
vShowValue?: Props | null,
vShowValue?: Props,
): SSRBuffer | Promise<SSRBuffer> {
const instance = (vnode.component = createComponentInstance(
vnode,
@ -128,7 +128,7 @@ export function renderComponentVNode(
function renderComponentSubTree(
instance: ComponentInternalInstance,
slotScopeId?: string,
vShowValue?: Props | null,
vShowValue?: Props,
): SSRBuffer | Promise<SSRBuffer> {
if (__DEV__) pushWarningContext(instance.vnode)
const comp = instance.type as Component
@ -235,7 +235,7 @@ export function renderVNode(
vnode: VNode,
parentComponent: ComponentInternalInstance,
slotScopeId?: string,
vShowValue?: Props | null,
vShowValue?: Props,
): void {
const { type, shapeFlag, children, dirs, props } = vnode
if (dirs) {