3
3
// Definitions by: Rahim Alwer <https://github.com/mihar-22>
4
4
5
5
import { queries , Queries , BoundFunction , EventType } from '@testing-library/dom'
6
- import { SvelteComponent } from 'svelte/types/runtime'
6
+ import { SvelteComponent , ComponentProps } from 'svelte/types/runtime'
7
7
8
8
export * from '@testing-library/dom'
9
9
10
- type SvelteComponentOptions = any
10
+ type SvelteComponentOptions < C extends SvelteComponent > = ComponentProps < C > | { props : ComponentProps < C > }
11
11
12
12
type Omit < T , K extends keyof T > = Pick < T , Exclude < keyof T , K > >
13
13
14
+ type Constructor < T > = new ( ...args : any [ ] ) => T ;
15
+
14
16
/**
15
17
* Render a Component into the Document.
16
18
*/
17
- export type RenderResult < Q extends Queries = typeof queries > = {
19
+ export type RenderResult < C extends SvelteComponent , Q extends Queries = typeof queries > = {
18
20
container : HTMLElement
19
- component : SvelteComponent
21
+ component : C
20
22
debug : ( el ?: HTMLElement | DocumentFragment ) => void
21
- rerender : ( options : SvelteComponentOptions ) => void
23
+ rerender : ( options : SvelteComponentOptions < C > ) => void
22
24
unmount : ( ) => void
23
25
} & { [ P in keyof Q ] : BoundFunction < Q [ P ] > }
24
26
@@ -27,17 +29,17 @@ export interface RenderOptions<Q extends Queries = typeof queries> {
27
29
queries ?: Q
28
30
}
29
31
30
- export function render (
31
- component : typeof SvelteComponent ,
32
- componentOptions ?: SvelteComponentOptions ,
32
+ export function render < C extends SvelteComponent > (
33
+ component : C ,
34
+ componentOptions ?: SvelteComponentOptions < C > ,
33
35
renderOptions ?: Omit < RenderOptions , 'queries' >
34
- ) : RenderResult
36
+ ) : RenderResult < C >
35
37
36
- export function render < Q extends Queries > (
37
- component : typeof SvelteComponent ,
38
- componentOptions ?: SvelteComponentOptions ,
38
+ export function render < C extends SvelteComponent , Q extends Queries > (
39
+ component : Constructor < C > ,
40
+ componentOptions ?: SvelteComponentOptions < C > ,
39
41
renderOptions ?: RenderOptions < Q > ,
40
- ) : RenderResult < Q >
42
+ ) : RenderResult < C , Q >
41
43
42
44
/**
43
45
* Unmounts trees that were mounted with render.
0 commit comments