-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathindex.d.ts
81 lines (67 loc) · 2.44 KB
/
index.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
71
72
73
74
75
76
77
78
79
80
81
// Type definitions for Svelte Testing Library
// Project: https://github.com/testing-library/svelte-testing-library
// Definitions by: Rahim Alwer <https://github.com/mihar-22>
import {queries, Queries, BoundFunction, EventType} from '@testing-library/dom'
import { SvelteComponentTyped } from 'svelte/types/runtime'
export * from '@testing-library/dom'
export interface SvelteComponentOptions<P extends Record<string, any> = any> {
target?: HTMLElement
anchor?: string
props?: P
context?: any
hydrate?: boolean
intro?: boolean
}
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
/**
* Render a Component into the Document.
*/
export type RenderResult<Q extends Queries = typeof queries> = {
container: Element
component: SvelteComponent
component: SvelteComponentTyped
debug: (el?: Element | DocumentFragment) => void
rerender: (options: SvelteComponentOptions) => void
unmount: () => void
} & { [P in keyof Q]: BoundFunction<Q[P]> }
export interface RenderOptions<Q extends Queries = typeof queries> {
container?: Element
queries?: Q
}
export function render(
component: SvelteComponentTyped,
componentOptions?: SvelteComponentOptions,
renderOptions?: Omit<RenderOptions, 'queries'>
): RenderResult
export function render<Q extends Queries>(
component: SvelteComponentTyped,
componentOptions?: SvelteComponentOptions,
renderOptions?: RenderOptions<Q>,
): RenderResult<Q>
export function render<
P extends Record<string, any> = any,
E extends Record<string, any> = any,
S extends Record<string, any> = any
>(
component: SvelteComponentTyped<P, E, S>,
componentOptions?: SvelteComponentOptions<P>,
renderOptions?: Omit<RenderOptions, "queries">
): RenderResult;
/**
* Unmounts trees that were mounted with render.
*/
export function cleanup(): void
/**
* Fires DOM events on an element provided by @testing-library/dom. Since Svelte needs to flush
* pending state changes via `tick`, these methods have been override and now return a promise.
*/
export type FireFunction = (element: Document | Element | Window, event: Event) => Promise<boolean>;
export type FireObject = {
[K in EventType]: (element: Document | Element | Window, options?: {}) => Promise<boolean>;
};
export const fireEvent: FireFunction & FireObject;
/**
* Calls a function or resolves a Promise and notifies Svelte to immediately flushes any pending
* state changes.
*/
export function act(fn?: Function | Promise<any>): Promise<void>