From: daiwei Date: Fri, 24 Jan 2025 06:18:27 +0000 (+0800) Subject: test: add tests X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=453aa03d43df12fb411f1eb6d57fbb79c2faa7a6;p=thirdparty%2Fvuejs%2Fcore.git test: add tests --- diff --git a/packages/compiler-core/__tests__/transforms/vSkip.spec.ts b/packages/compiler-core/__tests__/transforms/vSkip.spec.ts index 6987fb5202..2d7a74b7c4 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(`
`, {