Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
pinguet62 committed Nov 30, 2023
1 parent 082abab commit da5ae0b
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/component-meta/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,19 @@ const worker = (checker: ComponentMetaChecker, withTsconfig: boolean) => describ
expect(onBaz?.schema).toEqual([]);
});

test('reference-type-events for generic', () => {
const componentPath = path.resolve(__dirname, '../../../test-workspace/component-meta/generic/component.vue');
const meta = checker.getComponentMeta(componentPath);

expect(meta.type).toEqual(TypeMeta.Function);

const onBar = meta.events.find(event => event.name === 'bar');

expect(onBar).toBeDefined();
expect(onBar?.type).toEqual('number');
expect(onBar?.signature).toEqual('(e: "bar", data: number): void');
});

test('template-slots', () => {
const componentPath = path.resolve(__dirname, '../../../test-workspace/component-meta/template-slots/component.vue');
const meta = checker.getComponentMeta(componentPath);
Expand Down Expand Up @@ -563,6 +576,18 @@ const worker = (checker: ComponentMetaChecker, withTsconfig: boolean) => describ
expect(d).toBeDefined();
});

test('template-slots for generic', () => {
const componentPath = path.resolve(__dirname, '../../../test-workspace/component-meta/generic/component.vue');
const meta = checker.getComponentMeta(componentPath);

expect(meta.type).toEqual(TypeMeta.Function);

expect(meta.slots.find(slot =>
slot.name === 'default'
&& slot.type === '{ foo: number; }'
)).toBeDefined();
});

test('template-slots without a script block', () => {
const componentPath = path.resolve(__dirname, '../../../test-workspace/component-meta/template-slots/component-no-script.vue');
const meta = checker.getComponentMeta(componentPath);
Expand Down
53 changes: 53 additions & 0 deletions packages/tsc/tests/__snapshots__/dts.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,59 @@ export default _default;
"
`;

exports[`vue-tsc-dts > Input: generic/component.vue, Output: generic/component.vue.d.ts 1`] = `
"declare const _default: <T>(__VLS_props: {
onBar?: (data: number) => any;
foo: number;
} & import(\\"vue\\").VNodeProps & import(\\"vue\\").AllowedComponentProps & import(\\"vue\\").ComponentCustomProps, __VLS_ctx?: {
attrs: any;
emit: (e: 'bar', data: number) => void;
slots: Readonly<{
default?(data: {
foo: number;
}): any;
}>;
}, __VLS_expose?: (exposed: import(\\"vue\\").ShallowUnwrapRef<{
baz: number;
}>) => void, __VLS_setup?: Promise<{
props: {
onBar?: (data: number) => any;
foo: number;
} & import(\\"vue\\").VNodeProps & import(\\"vue\\").AllowedComponentProps & import(\\"vue\\").ComponentCustomProps;
expose(exposed: import(\\"vue\\").ShallowUnwrapRef<{
baz: number;
}>): void;
attrs: any;
slots: Readonly<{
default?(data: {
foo: number;
}): any;
}>;
emit: (e: 'bar', data: number) => void;
}>) => import(\\"vue\\").VNode<import(\\"vue\\").RendererNode, import(\\"vue\\").RendererElement, {
[key: string]: any;
}> & {
__ctx?: {
props: {
onBar?: (data: number) => any;
foo: number;
} & import(\\"vue\\").VNodeProps & import(\\"vue\\").AllowedComponentProps & import(\\"vue\\").ComponentCustomProps;
expose(exposed: import(\\"vue\\").ShallowUnwrapRef<{
baz: number;
}>): void;
attrs: any;
slots: Readonly<{
default?(data: {
foo: number;
}): any;
}>;
emit: (e: 'bar', data: number) => void;
};
};
export default _default;
"
`;
exports[`vue-tsc-dts > Input: non-component/component.ts, Output: non-component/component.d.ts 1`] = `
"declare const _default: {};
export default _default;
Expand Down
6 changes: 6 additions & 0 deletions test-workspace/component-meta/generic/component.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script setup lang="ts" generic="T">
defineProps<{ foo: number }>();
defineEmits<{ (e: 'bar', data: number): void }>();
defineExpose({ baz: {} as number });
defineSlots<{ default?(data: { foo: number }): any }>();
</script>

0 comments on commit da5ae0b

Please sign in to comment.