8000 test: change defineComponent to support JSX (#3384) · vuejs/language-tools@a899685 · GitHub
[go: up one dir, main page]

Skip to content

Commit a899685

Browse files
authored
test: change defineComponent to support JSX (#3384)
1 parent 0f039cf commit a899685

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

packages/vue-component-meta/tests/index.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,27 @@ const worker = (checker: ComponentMetaChecker, withTsconfig: boolean) => describ
732732

733733
expect(meta.type).toEqual(TypeMeta.Unknown);
734734
});
735+
736+
test('ts-component.tsx', () => {
737+
const componentPath = path.resolve(__dirname, '../../vue-test-workspace/vue-component-meta/ts-component/component.tsx');
738+
const meta = checker.getComponentMeta(componentPath);
739+
740+
expect(meta.type).toEqual(TypeMeta.Function);
741+
742+
const a = meta.props.find(prop =>
743+
prop.name === 'foo'
744+
&& prop.required === true
745+
&& prop.type === 'string'
746+
);
747+
const b = meta.props.find(prop =>
748+
prop.name === 'bar'
749+
&& prop.required === false
750+
&& prop.type === 'number | undefined'
751+
);
752+
753+
expect(a).toBeDefined();
754+
expect(b).toBeDefined();
755+
});
735756
});
736757

737758
const checkerOptions: MetaCheckerOptions = {

packages/vue-test-workspace/vue-component-meta/ts-component/component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { h, defineComponent } from "vue";
22
import { MyProps } from "./PropDefinitions";
33

44
export default defineComponent((props: MyProps) => {
5-
return h('pre', JSON.stringify(props, null, 2));
5+
return () => h('pre', JSON.stringify(props, null, 2));
66
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineComponent } from "vue";
2+
import { MyProps } from "./PropDefinitions";
3+
4+
export default defineComponent((props: MyProps) => {
5+
return () => <pre>
6+
{JSON.stringify(props, null, 2)}
7+
</pre>;
8+
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineComponent } from "vue";
22

3-
export const Foo = defineComponent((_: { foo: string; }) => { });
3+
export const Foo = defineComponent((_: { foo: string; }) => ()=> { });
44

5-
export const Bar = defineComponent((_: { bar?: number; }) => { });
5+
export const Bar = defineComponent((_: { bar?: number; }) => ()=> { });

0 commit comments

Comments
 (0)
0