Skip to content

Commit 66c65ac

Browse files
committed
fix: Match runtime type of baseElement in TypeScript types
1 parent 17e77a7 commit 66c65ac

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

types/index.d.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ export * from '@testing-library/dom'
1414
export type RenderResult<
1515
Q extends Queries = typeof queries,
1616
Container extends Element | DocumentFragment = HTMLElement,
17+
BaseElement extends Element | DocumentFragment = Container,
1718
> = {
1819
container: Container
19-
baseElement: Element
20+
baseElement: BaseElement
2021
debug: (
2122
baseElement?:
2223
| Element
@@ -33,6 +34,7 @@ export type RenderResult<
3334
export interface RenderOptions<
3435
Q extends Queries = typeof queries,
3536
Container extends Element | DocumentFragment = HTMLElement,
37+
BaseElement extends Element | DocumentFragment = Container,
3638
> {
3739
/**
3840
* By default, React Testing Library will create a div and append that div to the document.body. Your React component will be rendered in the created div. If you provide your own HTMLElement container via this option,
@@ -50,7 +52,7 @@ export interface RenderOptions<
5052
*
5153
* @see https://testing-library.com/docs/react-testing-library/api/#baseelement
5254
*/
53-
baseElement?: Element
55+
baseElement?: BaseElement
5456
/**
5557
* If `hydrate` is set to `true`, then it will render with `ReactDOM.hydrate`. This may be useful if you are using server-side
5658
* rendering and use ReactDOM.hydrate to mount your components.
@@ -81,10 +83,11 @@ type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
8183
export function render<
8284
Q extends Queries = typeof queries,
8385
Container extends Element | DocumentFragment = HTMLElement,
86+
BaseElement extends Element | DocumentFragment = Container,
8487
>(
8588
ui: React.ReactElement,
86-
options: RenderOptions<Q, Container>,
87-
): RenderResult<Q, Container>
89+
options: RenderOptions<Q, Container, BaseElement>,
90+
): RenderResult<Q, Container, BaseElement>
8891
export function render(
8992
ui: React.ReactElement,
9093
options?: Omit<RenderOptions, 'queries'>,

0 commit comments

Comments
 (0)