-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathindex.d.ts
65 lines (51 loc) · 2.17 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
// 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 { SvelteComponent, ComponentProps } from 'svelte/types/runtime'
export * from '@testing-library/dom'
type SvelteComponentOptions<C extends SvelteComponent> = ComponentProps<C> | {props: ComponentProps<C>}
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
type Constructor<T> = new (...args: any[]) => T;
/**
* Render a Component into the Document.
*/
export type RenderResult<C extends SvelteComponent, Q extends Queries = typeof queries> = {
container: HTMLElement
component: C
debug: (el?: HTMLElement | DocumentFragment) => void
rerender: (options: SvelteComponentOptions<C>) => void
unmount: () => void
} & { [P in keyof Q]: BoundFunction<Q[P]> }
export interface RenderOptions<Q extends Queries = typeof queries> {
container?: HTMLElement
queries?: Q
}
export function render<C extends SvelteComponent>(
component: Constructor<C>,
componentOptions?: SvelteComponentOptions<C>,
renderOptions?: Omit<RenderOptions, 'queries'>
): RenderResult<C>
export function render<C extends SvelteComponent, Q extends Queries>(
component: Constructor<C>,
componentOptions?: SvelteComponentOptions<C>,
renderOptions?: RenderOptions<Q>,
): RenderResult<C, Q>
/**
* 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>