Skip to content

Commit 2d70496

Browse files
committed
test: add props test
1 parent a01215e commit 2d70496

File tree

9 files changed

+156
-7
lines changed

9 files changed

+156
-7
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<template>
2+
<div></div>
3+
</template>
4+
<script setup>
5+
defineProps(['foo']);
6+
</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>
5+
defineProps({
6+
title: String,
7+
likes: Number
8+
})
9+
</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>
5+
const props = defineProps({
6+
title: String,
7+
likes: Number
8+
})
9+
</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+
const props = defineProps<{
6+
title: string
7+
likes?: number
8+
}>()
9+
</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+
defineProps<{
6+
title: string
7+
likes?: number
8+
}>()
9+
</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>
5+
export default {
6+
props: ['foo']
7+
};
8+
</script>
9+
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>
5+
export default {
6+
props: {
7+
title: String,
8+
likes: Number
9+
},
10+
};
11+
</script>
12+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`props test nameOnlyProps.vue 1`] = `"{"name":"/test/fixture/propsTest/nameOnlyProps.vue","props":"","size":100,"lastModifiedTime":0,"children":[]}"`;
4+
35
exports[`props test oneProps.vue 1`] = `"{"name":"/test/fixture/propsTest/oneProps.vue","props":{"data":{"type":"String","required":"true","default":"1"}},"size":192,"lastModifiedTime":0,"children":[]}"`;
46

57
exports[`props test twoProps.vue 1`] = `"{"name":"/test/fixture/propsTest/twoProps.vue","props":{"data":{"type":"String","required":"true","default":"1"},"data2":{"type":"Number","required":"false","default":1}},"size":283,"lastModifiedTime":0,"children":[]}"`;
8+
9+
exports[`props test typeOnlyProps.vue 1`] = `"{"name":"/test/fixture/propsTest/typeOnlyProps.vue","props":{"title":"String","likes":"Number"},"size":142,"lastModifiedTime":0,"children":[]}"`;

test/specs/props.test.ts

Lines changed: 89 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,61 @@ import {getImportDeclarationTree} from '../../src/server/Analyzer';
33
const fixturesDir = join(__dirname, '../fixture/');
44

55
describe('props test', () => {
6-
it('oneProps.vue', async () => {
6+
it('oneProps.vue', () => {
77
const filename = 'propsTest/oneProps';
8-
const declaration = await getImportDeclarationTree(join(fixturesDir, `${filename}.vue`), [], true);
8+
const declaration = getImportDeclarationTree(join(fixturesDir, `${filename}.vue`), [], true);
99
const json = JSON.stringify(declaration).slice(0);
1010

1111
expect(json).toMatchSnapshot();
1212
});
1313

1414

15-
it('twoProps.vue', async () => {
15+
it('nameOnlyProps.vue', () => {
16+
const filename = 'propsTest/nameOnlyProps';
17+
const declaration = getImportDeclarationTree(join(fixturesDir, `${filename}.vue`), [], true);
18+
19+
expect(declaration).toStrictEqual({
20+
name: `/test/fixture/${filename}.vue`,
21+
props: ['foo'],
22+
size: 100,
23+
lastModifiedTime: 0,
24+
children: [],
25+
});
26+
});
27+
28+
29+
it('typeOnlyProps.vue', () => {
30+
const filename = 'propsTest/typeOnlyProps';
31+
const declaration = getImportDeclarationTree(join(fixturesDir, `${filename}.vue`), [], true);
32+
33+
expect(declaration).toStrictEqual({
34+
name: `/test/fixture/${filename}.vue`,
35+
props: {
36+
title: 'String',
37+
likes: 'Number',
38+
},
39+
size: 142,
40+
lastModifiedTime: 0,
41+
children: [],
42+
});
43+
});
44+
45+
46+
it('twoProps.vue', () => {
1647
const filename = 'propsTest/twoProps';
17-
const declaration = await getImportDeclarationTree(join(fixturesDir, `${filename}.vue`), [], true);
48+
const declaration = getImportDeclarationTree(join(fixturesDir, `${filename}.vue`), [], true);
1849
const json = JSON.stringify(declaration).slice(0);
1950

2051
expect(json).toMatchSnapshot();
2152
});
2253

2354

24-
it('defineTwoProps.vue', async () => {
55+
it('defineTwoProps.vue', () => {
2556
const filename = 'propsTest/defineTwoProps';
26-
const declaration = await getImportDeclarationTree(join(fixturesDir, `${filename}.vue`), [], true);
57+
const declaration = getImportDeclarationTree(join(fixturesDir, `${filename}.vue`), [], true);
2758

2859
expect(declaration).toStrictEqual({
29-
name: '/test/fixture/propsTest/defineTwoProps.vue',
60+
name: `/test/fixture/${filename}.vue`,
3061
props: {
3162
data: {
3263
type: 'String',
@@ -44,4 +75,55 @@ describe('props test', () => {
4475
children: [],
4576
});
4677
});
78+
79+
80+
it('defineTypeOnlyProps.vue', () => {
81+
const filename = 'propsTest/defineTypeOnlyProps';
82+
const declaration = getImportDeclarationTree(join(fixturesDir, `${filename}.vue`), [], true);
83+
84+
expect(declaration).toStrictEqual({
85+
name: `/test/fixture/${filename}.vue`,
86+
props: {
87+
title: 'String',
88+
likes: 'Number',
89+
},
90+
size: 112,
91+
lastModifiedTime: 0,
92+
children: [],
93+
});
94+
});
95+
96+
97+
it('defineTypeOnlyPropsWithTypeScript.vue', () => {
98+
const filename = 'propsTest/defineTypeOnlyPropsWithTypeScript';
99+
const declaration = getImportDeclarationTree(join(fixturesDir, `${filename}.vue`), [], true);
100+
101+
expect(declaration).toStrictEqual({
102+
name: `/test/fixture/${filename}.vue`,
103+
props: {
104+
title: 'string',
105+
likes: 'number',
106+
},
107+
size: 125,
108+
lastModifiedTime: 0,
109+
children: [],
110+
});
111+
});
112+
113+
114+
it('defineTypeOnlyPropsVariablesWithTypeScript.vue', () => {
115+
const filename = 'propsTest/defineTypeOnlyPropsVariablesWithTypeScript';
116+
const declaration = getImportDeclarationTree(join(fixturesDir, `${filename}.vue`), [], true);
117+
118+
expect(declaration).toStrictEqual({
119+
name: `/test/fixture/${filename}.vue`,
120+
props: {
121+
foo: 'string',
122+
bar: '[number]',
123+
},
124+
size: 125,
125+
lastModifiedTime: 0,
126+
children: [],
127+
});
128+
});
47129
});

0 commit comments

Comments
 (0)