1 | import { queries, Queries, BoundFunction } from '@testing-library/dom'
|
2 | import { act as preactAct } from 'preact/test-utils'
|
3 | import { ComponentChild } from 'preact'
|
4 |
|
5 | export * from '@testing-library/dom'
|
6 |
|
7 | export type RenderResult<Q extends Queries = typeof queries> = {
|
8 | container: Element
|
9 | baseElement: Element
|
10 | debug: (baseElement?: Element | DocumentFragment) => void
|
11 | rerender: (ui: ComponentChild) => void
|
12 | unmount: () => boolean
|
13 | asFragment: () => DocumentFragment
|
14 | } & { [P in keyof Q]: BoundFunction<Q[P]> }
|
15 |
|
16 | export interface RenderOptions<Q extends Queries = typeof queries> {
|
17 | container?: Element
|
18 | baseElement?: Element
|
19 | queries?: Q
|
20 | wrapper?: ComponentChild
|
21 | }
|
22 |
|
23 | type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | export function render(ui: ComponentChild, options?: Omit<RenderOptions, 'queries'>): RenderResult
|
29 |
|
30 | export function render<Q extends Queries>(
|
31 | ui: ComponentChild,
|
32 | options: RenderOptions<Q>,
|
33 | ): RenderResult<Q>
|
34 |
|
35 | /**
|
36 | * Unmounts Preact trees that were mounted with render.
|
37 | */
|
38 | export function cleanup(): void
|
39 |
|
40 | /**
|
41 | * Simply calls preact/test-utils.act(cb)
|
42 | *
|
43 | * If that's not available (older version of preact) then it
|
44 | * simply calls the given callback immediately
|
45 | */
|
46 | export const act: typeof preactAct extends undefined
|
47 | ? (callback: () => void) => void
|
48 | : typeof preactAct
|
49 |
|
\ | No newline at end of file |