From 47e0b7187bc3c275251fe25acd13a15e0593d81a Mon Sep 17 00:00:00 2001 From: Rizumu Ayaka Date: Wed, 29 Nov 2023 19:33:32 +0800 Subject: [PATCH] test: v-pre --- .../__snapshots__/compile.test.ts.snap | 52 +++++++++++++++++++ .../compiler-vapor/__tests__/compile.test.ts | 46 ++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/packages/compiler-vapor/__tests__/__snapshots__/compile.test.ts.snap b/packages/compiler-vapor/__tests__/__snapshots__/compile.test.ts.snap index 92181bc6e..53f759e8a 100644 --- a/packages/compiler-vapor/__tests__/__snapshots__/compile.test.ts.snap +++ b/packages/compiler-vapor/__tests__/__snapshots__/compile.test.ts.snap @@ -125,6 +125,58 @@ export function render() { " `; +exports[`compile > directives > v-pre > basic 1`] = ` +"import { template } from 'vue/vapor'; +const t0 = template('
{{ bar }}
'); +export function render() { + const n0 = t0(); + return n0; +} +" +`; + +exports[`compile > directives > v-pre > self-closing v-pre 1`] = ` +"import { template, children, createTextNode, append, effect, setAttr, setText } from 'vue/vapor'; +const t0 = template('
'); +export function render() { + const n0 = t0(); + const { + 1: [n1], + } = children(n0); + const n2 = createTextNode(bar); + append(n1, n2); + effect(() => { + setAttr(n1, 'id', undefined, foo); + }); + effect(() => { + setText(n2, undefined, bar); + }); + return n0; +} +" +`; + +exports[`compile > directives > v-pre > should not affect siblings after it 1`] = ` +"import { template, children, createTextNode, append, effect, setAttr, setText } from 'vue/vapor'; +const t0 = template('
{{ bar }}
'); +export function render() { + const n0 = t0(); + const { + 1: [n1], + } = children(n0); + const n2 = createTextNode(bar.value); + append(n1, n2); + effect(() => { + setAttr(n1, 'id', undefined, foo.value); + }); + effect(() => { + setText(n2, undefined, bar.value); + }); + return n0; +} +" +`; + exports[`compile > directives > v-text > no expression 1`] = ` "import { template, children, effect, setText } from 'vue/vapor'; const t0 = template('
'); diff --git a/packages/compiler-vapor/__tests__/compile.test.ts b/packages/compiler-vapor/__tests__/compile.test.ts index e9766a806..30cb72f66 100644 --- a/packages/compiler-vapor/__tests__/compile.test.ts +++ b/packages/compiler-vapor/__tests__/compile.test.ts @@ -177,5 +177,51 @@ describe('compile', () => { expect(code).not.contains('effect') }) }) + + describe('v-pre', () => { + test('basic', async () => { + const code = await compile( + `
{{ bar }}
\n`, + { + bindingMetadata: { + foo: BindingTypes.SETUP_REF, + bar: BindingTypes.SETUP_REF, + }, + }, + ) + + expect(code).toMatchSnapshot() + expect(code).contains('
{{ bar }}
') + expect(code).not.contains('effect') + }) + + // TODO: support multiple root nodes and components + test('should not affect siblings after it', async () => { + const code = await compile( + `
{{ bar }}
\n` + + `
{{ bar }}
`, + { + bindingMetadata: { + foo: BindingTypes.SETUP_REF, + bar: BindingTypes.SETUP_REF, + }, + }, + ) + + expect(code).toMatchSnapshot() + // Waiting for TODO, There should be more here. + }) + + // TODO: support multiple root nodes and components + test('self-closing v-pre', async () => { + const code = await compile( + `
\n
{{ bar }}
`, + ) + + expect(code).toMatchSnapshot() + expect(code).contains('
') + // Waiting for TODO, There should be more here. + }) + }) }) })