Skip to content

Add tests for optional props on Svelte components #344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,24 @@ describe('TypeScript Plugin#DiagnosticsProvider', () => {
]);
});

it('properly support optional props on Svelte components', async () => {
const { provider, document } = setup('svelteOptional.astro');

const diagnostics = await provider.getDiagnostics(document);

expect(diagnostics).to.deep.equal([
{
code: 2322,
message:
"Type '{}' is not assignable to type 'IntrinsicAttributes & { notOptional: any; optional?: string; }'.\nProperty 'notOptional' is missing in type '{}' but required in type '{ notOptional: any; optional?: string; }'.",
range: Range.create(4, 1, 4, 20),
severity: DiagnosticSeverity.Error,
source: 'ts',
tags: [],
},
]);
});

it('provide diagnostics for invalid framework components', async () => {
const { provider, document } = setup('frameworkComponentError.astro');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('TypeScript Plugin#HoverProvider', () => {

expect(hoverInfo).to.deep.equal(<Hover>{
contents:
'```typescript\n(alias) function Sveltecomment(_props: typeof Props): any\nimport Sveltecomment\n```\n---\nMy super Svelte component!',
'```typescript\n(alias) function Sveltecomment(_props: typeof Component.props): any\nimport Sveltecomment\n```\n---\nMy super Svelte component!',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor update because shape of output changed here

range: Range.create(4, 1, 4, 14),
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<script>
export const optional = "Hey"
export let notOptional
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
import SvelteOptionalProps from "./SvelteOptionalProps.svelte"
---

<SvelteOptionalProps></SvelteOptionalProps>