|
1 | | -import {getQueriesForElement} from 'dom-testing-library' |
| 1 | +import {queries, BoundFunction} from 'dom-testing-library' |
2 | 2 |
|
3 | 3 | export * from 'dom-testing-library' |
4 | 4 |
|
5 | | -type GetsAndQueries = ReturnType<typeof getQueriesForElement> |
| 5 | +interface Query extends Function { |
| 6 | + (container: HTMLElement, ...args): HTMLElement[] | HTMLElement | null |
| 7 | +} |
| 8 | + |
| 9 | +interface Queries { |
| 10 | + [T: string]: Query |
| 11 | +} |
6 | 12 |
|
7 | | -export interface RenderResult extends GetsAndQueries { |
| 13 | +export type RenderResult<Q extends Queries = typeof queries> = { |
8 | 14 | container: HTMLElement |
9 | 15 | baseElement: HTMLElement |
10 | 16 | debug: (baseElement?: HTMLElement | DocumentFragment) => void |
11 | 17 | rerender: (ui: React.ReactElement<any>) => void |
12 | 18 | unmount: () => boolean |
13 | 19 | asFragment: () => DocumentFragment |
14 | | -} |
| 20 | +} & {[P in keyof Q]: BoundFunction<Q[P]>} |
15 | 21 |
|
16 | | -export interface RenderOptions { |
| 22 | +export interface RenderOptions<Q extends Queries = typeof queries> { |
17 | 23 | container?: HTMLElement |
18 | 24 | baseElement?: HTMLElement |
19 | 25 | hydrate?: boolean |
| 26 | + queries?: Q |
20 | 27 | } |
21 | 28 |
|
| 29 | +type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>> |
| 30 | + |
22 | 31 | /** |
23 | 32 | * Render into a container which is appended to document.body. It should be used with cleanup. |
24 | 33 | */ |
25 | 34 | export function render( |
26 | 35 | ui: React.ReactElement<any>, |
27 | | - options?: RenderOptions, |
| 36 | + options?: Omit<RenderOptions, 'queries'>, |
28 | 37 | ): RenderResult |
| 38 | +export function render<Q extends Queries>( |
| 39 | + ui: React.ReactElement<any>, |
| 40 | + options: RenderOptions<Q>, |
| 41 | +): RenderResult<Q> |
29 | 42 |
|
30 | 43 | /** |
31 | 44 | * Unmounts React trees that were mounted with render. |
|
0 commit comments