Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit 3f5dcf5

Browse files
committed
test: add test for dynamic components
1 parent 8c2e2a4 commit 3f5dcf5

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

playground/Bar.vue

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<div>Bar</div>
3+
</template>

playground/Foo.vue

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<div>Foo</div>
3+
</template>

playground/HelloWorld.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
</button>
77
<div>{{ count }} x 2 = {{ doubled }}</div>
88
<button @click="dec()" v-html="decText" />
9+
<component :is="count > 2 ? Foo : Bar" />
910
</div>
1011
</template>
1112

1213
<script setup lang="ts">
1314
import { ref, computed, watch } from '@vue/composition-api'
15+
import Foo from './Foo.vue'
16+
import Bar from './Bar.vue'
1417
1518
const props = withDefaults(defineProps<{ msg: string; name: string | number }>(), { msg: 'Hello' })
1619
const emit = defineEmits(['update'])
@@ -23,7 +26,7 @@ function inc() {
2326
}
2427
2528
function dec() {
26-
count.value += 1
29+
count.value -= 1
2730
}
2831
2932
const decText = '<b>Dec</b>'

test/__snapshots__/transform.test.ts.snap

+20-1
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,20 @@ export default __sfc_main;
252252
"
253253
`;
254254
255+
exports[`transform playground Bar.vue 1`] = `
256+
"<template>
257+
<div>Bar</div>
258+
</template>
259+
"
260+
`;
261+
262+
exports[`transform playground Foo.vue 1`] = `
263+
"<template>
264+
<div>Foo</div>
265+
</template>
266+
"
267+
`;
268+
255269
exports[`transform playground HelloWorld.vue 1`] = `
256270
"<template>
257271
<div>
@@ -261,11 +275,14 @@ exports[`transform playground HelloWorld.vue 1`] = `
261275
</button>
262276
<div>{{ count }} x 2 = {{ doubled }}</div>
263277
<button @click=\\"dec()\\" v-html=\\"decText\\" />
278+
<component :is=\\"count > 2 ? Foo : Bar\\" />
264279
</div>
265280
</template>
266281
267282
<script lang=\\"ts\\">
268283
import { ref, computed, watch } from '@vue/composition-api';
284+
import Foo from './Foo.vue';
285+
import Bar from './Bar.vue';
269286
const __sfc_main = {
270287
name: 'App'
271288
};
@@ -294,12 +311,14 @@ __sfc_main.setup = (__props, __ctx) => {
294311
}
295312
296313
function dec() {
297-
count.value += 1;
314+
count.value -= 1;
298315
}
299316
300317
const decText = '<b>Dec</b>';
301318
watch(count, value => emit('update', value));
302319
return {
320+
Foo,
321+
Bar,
303322
count,
304323
doubled,
305324
inc,

0 commit comments

Comments
 (0)