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>`) ).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', () => { describe('template v-model', () => {

View File

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

View File

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