Skip to content

Commit

Permalink
test: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edison1105 committed Jan 24, 2025
1 parent 6c17a37 commit 453aa03
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions packages/compiler-core/__tests__/transforms/vSkip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,53 @@ describe('compiler: v-skip', () => {
expect(generate(root).code).toMatchSnapshot()
})

test.todo('on component with dynamic slot + default slot', () => {
const { root, node } = parseWithSkipTransform(
`<Comp v-skip="ok">
<template #[foo]>foo</template>
<template #default>default</template>
</Comp>`,
)
expect(node.type).toBe(NodeTypes.SKIP)
expect((node.test as SimpleExpressionNode).content).toBe(`_ctx.ok`)
expect((node.consequent as IfBranchNode).children.length).toBe(1)
expect((node.consequent as IfBranchNode).children[0].type).toBe(
NodeTypes.TEXT,
)
expect(
((node.consequent as IfBranchNode).children[0] as any).content,
).toBe(`default`)
expect(node.alternate.children.length).toBe(1)
expect((node.alternate.children[0] as ElementNode).tagType).toBe(
ElementTypes.COMPONENT,
)
expect((node.alternate.children[0] as ElementNode).tag).toBe(`Comp`)
expect(generate(root).code).toMatchSnapshot()
})

test.todo('on component with name default slot + v-if', () => {
const { root, node } = parseWithSkipTransform(
`<Comp v-skip="ok">
<template v-if="yes" #default>default</template>
</Comp>`,
)
expect(node.type).toBe(NodeTypes.SKIP)
expect((node.test as SimpleExpressionNode).content).toBe(`_ctx.ok`)
expect(node.consequent.type === NodeTypes.JS_CALL_EXPRESSION).toBe(true)
expect(generate(root).code).toMatchSnapshot()
})

test.todo('on component with implicit default slot + v-if', () => {
const { root, node } = parseWithSkipTransform(
`<Comp v-skip="ok">
<span v-if="yes">default</span>
</Comp>`,
)
expect(node.type).toBe(NodeTypes.SKIP)
expect((node.test as SimpleExpressionNode).content).toBe(`_ctx.ok`)
expect(generate(root).code).toMatchSnapshot()
})

test('on dynamic component', () => {
const { root, node } = parseWithSkipTransform(
`<component :is="Comp" v-skip="ok">
Expand Down Expand Up @@ -423,6 +470,21 @@ describe('compiler: v-skip', () => {
])
})

test('on component with only dynamic slot', () => {
const onError = vi.fn()
parseWithSkipTransform(
`<Comp v-skip="ok">
<template #[foo]>foo</template>
</Comp>`,
{ onError },
)
expect(onError.mock.calls[0]).toMatchObject([
{
code: ErrorCodes.X_V_SKIP_UNEXPECTED_SLOT,
},
])
})

test('with v-for', () => {
const onError = vi.fn()
parseWithSkipTransform(`<div v-for="i in items" v-skip="ok"/>`, {
Expand Down

0 comments on commit 453aa03

Please sign in to comment.