From 453aa03d43df12fb411f1eb6d57fbb79c2faa7a6 Mon Sep 17 00:00:00 2001 From: daiwei Date: Fri, 24 Jan 2025 14:18:27 +0800 Subject: [PATCH] test: add tests --- .../__tests__/transforms/vSkip.spec.ts | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/packages/compiler-core/__tests__/transforms/vSkip.spec.ts b/packages/compiler-core/__tests__/transforms/vSkip.spec.ts index 6987fb52022..2d7a74b7c47 100644 --- a/packages/compiler-core/__tests__/transforms/vSkip.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vSkip.spec.ts @@ -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( + ` + + + `, + ) + 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( + ` + + `, + ) + 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( + ` + default + `, + ) + 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( ` @@ -423,6 +470,21 @@ describe('compiler: v-skip', () => { ]) }) + test('on component with only dynamic slot', () => { + const onError = vi.fn() + parseWithSkipTransform( + ` + + `, + { onError }, + ) + expect(onError.mock.calls[0]).toMatchObject([ + { + code: ErrorCodes.X_V_SKIP_UNEXPECTED_SLOT, + }, + ]) + }) + test('with v-for', () => { const onError = vi.fn() parseWithSkipTransform(`
`, {