From 41c258903efb5aa914a71ffdb5e9cda0efd998d5 Mon Sep 17 00:00:00 2001 From: daiwei Date: Thu, 6 Mar 2025 15:10:57 +0800 Subject: [PATCH] wip: add tests --- .../transforms/TransformTransition.spec.ts | 55 +++++++++++++++++++ .../TransformTransition.spec.ts.snap | 53 ++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 packages/compiler-vapor/__tests__/transforms/TransformTransition.spec.ts create mode 100644 packages/compiler-vapor/__tests__/transforms/__snapshots__/TransformTransition.spec.ts.snap diff --git a/packages/compiler-vapor/__tests__/transforms/TransformTransition.spec.ts b/packages/compiler-vapor/__tests__/transforms/TransformTransition.spec.ts new file mode 100644 index 0000000000..28425e5fd3 --- /dev/null +++ b/packages/compiler-vapor/__tests__/transforms/TransformTransition.spec.ts @@ -0,0 +1,55 @@ +import { makeCompile } from './_utils' +import { + transformChildren, + transformElement, + transformText, + transformVBind, + transformVIf, + transformVSlot, +} from '@vue/compiler-vapor' +import { expect } from 'vitest' + +const compileWithElementTransform = makeCompile({ + nodeTransforms: [ + transformText, + transformVIf, + transformElement, + transformVSlot, + transformChildren, + ], + directiveTransforms: { + bind: transformVBind, + }, +}) + +describe('compiler: transition', () => { + test('basic', () => { + const { code } = compileWithElementTransform( + `

foo

`, + ) + expect(code).toMatchSnapshot() + }) + + test('work with v-if', () => { + const { code } = compileWithElementTransform( + `

foo

`, + ) + + expect(code).toMatchSnapshot() + // n2 should have a key + expect(code).contains('n2.key = 2') + }) + + test('work with dynamic keyed children', () => { + const { code } = compileWithElementTransform( + ` +

foo

+
`, + ) + + expect(code).toMatchSnapshot() + expect(code).contains('_createKeyedFragment(() => _ctx.key') + // should preserve key + expect(code).contains('n0.key = _ctx.key') + }) +}) diff --git a/packages/compiler-vapor/__tests__/transforms/__snapshots__/TransformTransition.spec.ts.snap b/packages/compiler-vapor/__tests__/transforms/__snapshots__/TransformTransition.spec.ts.snap new file mode 100644 index 0000000000..d515ed7a28 --- /dev/null +++ b/packages/compiler-vapor/__tests__/transforms/__snapshots__/TransformTransition.spec.ts.snap @@ -0,0 +1,53 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`compiler: transition > basic 1`] = ` +"import { VaporTransition as _VaporTransition, createComponent as _createComponent, template as _template } from 'vue'; +const t0 = _template("

foo

") + +export function render(_ctx) { + const n1 = _createComponent(_VaporTransition, { appear: () => ("") }, { + "default": () => { + const n0 = t0() + return n0 + } + }, true) + return n1 +}" +`; + +exports[`compiler: transition > work with dynamic keyed children 1`] = ` +"import { VaporTransition as _VaporTransition, createKeyedFragment as _createKeyedFragment, createComponent as _createComponent, template as _template } from 'vue'; +const t0 = _template("

foo

") + +export function render(_ctx) { + const n1 = _createComponent(_VaporTransition, null, { + "default": () => { + return _createKeyedFragment(() => _ctx.key, () => { + const n0 = t0() + n0.key = _ctx.key + return n0 + }) + } + }, true) + return n1 +}" +`; + +exports[`compiler: transition > work with v-if 1`] = ` +"import { VaporTransition as _VaporTransition, createIf as _createIf, createComponent as _createComponent, template as _template } from 'vue'; +const t0 = _template("

foo

") + +export function render(_ctx) { + const n3 = _createComponent(_VaporTransition, null, { + "default": () => { + const n0 = _createIf(() => (_ctx.show), () => { + const n2 = t0() + n2.key = 2 + return n2 + }) + return n0 + } + }, true) + return n3 +}" +`; -- 2.47.2