Skip to content

Commit a1dcd41

Browse files
authored
Add tests for optional props on Svelte components (#344)
* Add tests for Svelte optional props * Fix expected message * Update to latest Svelte integration
1 parent 081cf24 commit a1dcd41

File tree

6 files changed

+211
-25
lines changed

6 files changed

+211
-25
lines changed

packages/language-server/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
"vscode-uri": "^3.0.3"
3232
},
3333
"devDependencies": {
34-
"@astrojs/svelte": "^0.2.1",
35-
"@astrojs/vue": "^0.2.1",
34+
"@astrojs/svelte": "^0.5.0",
35+
"@astrojs/vue": "^0.5.0",
3636
"@types/chai": "^4.3.0",
3737
"@types/mocha": "^9.1.0",
3838
"@types/sinon": "^10.0.11",

packages/language-server/test/plugins/typescript/features/DiagnosticsProvider.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,24 @@ describe('TypeScript Plugin#DiagnosticsProvider', () => {
112112
]);
113113
});
114114

115+
it('properly support optional props on Svelte components', async () => {
116+
const { provider, document } = setup('svelteOptional.astro');
117+
118+
const diagnostics = await provider.getDiagnostics(document);
119+
120+
expect(diagnostics).to.deep.equal([
121+
{
122+
code: 2322,
123+
message:
124+
"Type '{}' is not assignable to type 'IntrinsicAttributes & { notOptional: any; optional?: string; }'.\n Property 'notOptional' is missing in type '{}' but required in type '{ notOptional: any; optional?: string; }'.",
125+
range: Range.create(4, 1, 4, 20),
126+
severity: DiagnosticSeverity.Error,
127+
source: 'ts',
128+
tags: [],
129+
},
130+
]);
131+
});
132+
115133
it('provide diagnostics for invalid framework components', async () => {
116134
const { provider, document } = setup('frameworkComponentError.astro');
117135

packages/language-server/test/plugins/typescript/features/HoverProvider.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('TypeScript Plugin#HoverProvider', () => {
6767

6868
expect(hoverInfo).to.deep.equal(<Hover>{
6969
contents:
70-
'```typescript\n(alias) function Sveltecomment(_props: typeof Props): any\nimport Sveltecomment\n```\n---\nMy super Svelte component!',
70+
'```typescript\n(alias) function Sveltecomment(_props: typeof Component.props): any\nimport Sveltecomment\n```\n---\nMy super Svelte component!',
7171
range: Range.create(4, 1, 4, 14),
7272
});
7373
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<script>
2+
export const optional = "Hey"
3+
export let notOptional
4+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
import SvelteOptionalProps from "./SvelteOptionalProps.svelte"
3+
---
4+
5+
<SvelteOptionalProps></SvelteOptionalProps>

0 commit comments

Comments
 (0)