Skip to content

Commit

Permalink
chore: add missing test
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Jul 28, 2022
1 parent 7d2fcea commit 817f1dc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
3 changes: 1 addition & 2 deletions packages/vue-component-meta/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ export function createComponentMetaChecker(tsconfigPath: string) {
const properties = type.getProperties();
return properties.map(prop => ({
name: prop.getName(),
propsType: typeChecker.typeToString(typeChecker.getTypeOfSymbolAtLocation(typeChecker.getTypeOfSymbolAtLocation(prop, symbolNode!).getCallSignatures()[0].parameters[0], symbolNode!)),
// props: {}, // TODO
type: typeChecker.typeToString(typeChecker.getTypeOfSymbolAtLocation(typeChecker.getTypeOfSymbolAtLocation(prop, symbolNode!).getCallSignatures()[0].parameters[0], symbolNode!)),
description: ts.displayPartsToString(prop.getDocumentationComment(typeChecker)),
}));
}
Expand Down
30 changes: 25 additions & 5 deletions packages/vue-component-meta/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,15 @@ describe(`vue-component-meta`, () => {

const a = meta.slots.find(slot =>
slot.name === 'default'
&& slot.propsType === '{ num: number; }'
&& slot.type === '{ num: number; }'
);
const b = meta.slots.find(slot =>
slot.name === 'named-slot'
&& slot.propsType === '{ str: string; }'
&& slot.type === '{ str: string; }'
);
const c = meta.slots.find(slot =>
slot.name === 'vbind'
&& slot.propsType === '{ num: number; str: string; }'
&& slot.type === '{ num: number; str: string; }'
);

expect(a).toBeDefined();
Expand All @@ -359,11 +359,11 @@ describe(`vue-component-meta`, () => {

const a = meta.slots.find(slot =>
slot.name === 'default'
&& slot.propsType === '{ num: number; }'
&& slot.type === '{ num: number; }'
);
const b = meta.slots.find(slot =>
slot.name === 'foo'
&& slot.propsType === '{ str: string; }'
&& slot.type === '{ str: string; }'
);

expect(a).toBeDefined();
Expand All @@ -384,6 +384,26 @@ describe(`vue-component-meta`, () => {
expect(counter).toBeDefined();
});

test('ts-component', () => {

const componentPath = path.resolve(__dirname, '../../vue-test-workspace/vue-component-meta/ts-component/component.ts');
const meta = checker.getComponentMeta(componentPath);

const a = meta.props.find(prop =>
prop.name === 'foo'
&& prop.required === true
&& prop.type === 'string'
);
const b = meta.props.find(prop =>
prop.name === 'bar'
&& prop.required === false
&& prop.type === 'number | undefined'
);

expect(a).toBeDefined();
expect(b).toBeDefined();
});

test('ts-named-exports', () => {

const componentPath = path.resolve(__dirname, '../../vue-test-workspace/vue-component-meta/ts-named-export/component.ts');
Expand Down

0 comments on commit 817f1dc

Please sign in to comment.