-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathrender-runes.test-d.ts
70 lines (56 loc) · 2.14 KB
/
render-runes.test-d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { expectTypeOf } from 'expect-type'
import { describe, test, vi } from 'vitest'
import * as subject from '../index.js'
import LegacyComponent from './fixtures/Typed.svelte'
import Component from './fixtures/TypedRunes.svelte'
describe('types', () => {
test('render is a function that accepts a Svelte component', () => {
subject.render(Component, { name: 'Alice', count: 42 })
subject.render(Component, { props: { name: 'Alice', count: 42 } })
})
test('rerender is a function that accepts partial props', async () => {
const { rerender } = subject.render(Component, { name: 'Alice', count: 42 })
await rerender({ name: 'Bob' })
await rerender({ count: 0 })
})
test('invalid prop types are rejected', () => {
// @ts-expect-error: name should be a string
subject.render(Component, { name: 42 })
// @ts-expect-error: name should be a string
subject.render(Component, { props: { name: 42 } })
})
test('render result has container and component', () => {
const result = subject.render(Component, { name: 'Alice', count: 42 })
expectTypeOf(result).toExtend<{
container: HTMLElement
baseElement: HTMLElement
component: { hello: string }
debug: (el?: HTMLElement) => void
rerender: (props: { name?: string; count?: number }) => Promise<void>
unmount: () => void
}>()
})
})
describe('legacy component types', () => {
test('render accepts events', () => {
const onGreeting = vi.fn()
subject.render(LegacyComponent, {
props: { name: 'Alice', count: 42 },
events: { greeting: onGreeting },
})
})
test('component $set and $on are not allowed', () => {
const onGreeting = vi.fn()
const { component } = subject.render(LegacyComponent, {
name: 'Alice',
count: 42,
})
expectTypeOf(component).toExtend<{ hello: string }>()
// @ts-expect-error: Svelte 5 mount does not return `$set`
component.$on('greeting', onGreeting)
// @ts-expect-error: Svelte 5 mount does not return `$set`
component.$set({ name: 'Bob' })
// @ts-expect-error: Svelte 5 mount does not return `$destroy`
component.$destroy()
})
})