Skip to content

Commit cd148c8

Browse files
committed
test: add test case for withDefaults
1 parent 6075ee8 commit cd148c8

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<template>
2+
<div></div>
3+
</template>
4+
<script setup>
5+
withDefaults(defineProps({
6+
title: String,
7+
likes: Number
8+
}), {
9+
title: 'title',
10+
likes: 'links',
11+
});
12+
</script>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<template>
2+
<div></div>
3+
</template>
4+
<script setup lang="ts">
5+
withDefaults(defineProps<{title: string, likes?: number}>(), {
6+
title: 'title',
7+
likes: 3,
8+
});
9+
</script>

test/specs/props.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,40 @@ describe('props test', () => {
225225
});
226226

227227

228+
it('definePropsWithDefaults.vue', () => {
229+
const filename = 'propsTest/definePropsWithDefaults';
230+
const declaration = getImportDeclarationTree(join(fixturesDir, `${filename}.vue`), [], true);
231+
232+
expect(declaration).toStrictEqual({
233+
name: `/test/fixture/${filename}.vue`,
234+
props: `defineProps({
235+
title: String,
236+
likes: Number
237+
})`,
238+
size: 178,
239+
lastModifiedTime: 0,
240+
children: [],
241+
});
242+
});
243+
244+
245+
it('definePropsWithDefaultsWithTypeScript.vue', () => {
246+
const filename = 'propsTest/definePropsWithDefaultsWithTypeScript';
247+
const declaration = getImportDeclarationTree(join(fixturesDir, `${filename}.vue`), [], true);
248+
249+
expect(declaration).toStrictEqual({
250+
name: `/test/fixture/${filename}.vue`,
251+
props: `defineProps<{
252+
title: string,
253+
likes?: number
254+
}>`,
255+
size: 175,
256+
lastModifiedTime: 0,
257+
children: [],
258+
});
259+
});
260+
261+
228262
it('oneProps.vue', () => {
229263
const filename = 'propsTest/oneProps';
230264
const declaration = getImportDeclarationTree(join(fixturesDir, `${filename}.vue`), [], true);

0 commit comments

Comments
 (0)