|
1 | 1 | import { expectTypeOf } from 'expect-type' |
2 | | -import { describe, test } from 'vitest' |
| 2 | +import { describe, test, vi } from 'vitest' |
3 | 3 |
|
4 | 4 | import * as subject from '../index.js' |
| 5 | +import LegacyComponent from './fixtures/Typed.svelte' |
5 | 6 | import Component from './fixtures/TypedRunes.svelte' |
6 | 7 |
|
7 | 8 | describe('types', () => { |
@@ -37,3 +38,32 @@ describe('types', () => { |
37 | 38 | }>() |
38 | 39 | }) |
39 | 40 | }) |
| 41 | + |
| 42 | +describe('legacy component types', () => { |
| 43 | + test('render accepts events', () => { |
| 44 | + const onGreeting = vi.fn() |
| 45 | + subject.render(LegacyComponent, { |
| 46 | + props: { name: 'Alice', count: 42 }, |
| 47 | + events: { greeting: onGreeting }, |
| 48 | + }) |
| 49 | + }) |
| 50 | + |
| 51 | + test('component $set and $on are not allowed', () => { |
| 52 | + const onGreeting = vi.fn() |
| 53 | + const { component } = subject.render(LegacyComponent, { |
| 54 | + name: 'Alice', |
| 55 | + count: 42, |
| 56 | + }) |
| 57 | + |
| 58 | + expectTypeOf(component).toMatchTypeOf<{ hello: string }>() |
| 59 | + |
| 60 | + // @ts-expect-error: Svelte 5 mount does not return `$set` |
| 61 | + component.$on('greeting', onGreeting) |
| 62 | + |
| 63 | + // @ts-expect-error: Svelte 5 mount does not return `$set` |
| 64 | + component.$set({ name: 'Bob' }) |
| 65 | + |
| 66 | + // @ts-expect-error: Svelte 5 mount does not return `$destroy` |
| 67 | + component.$destroy() |
| 68 | + }) |
| 69 | +}) |
0 commit comments