Skip to content

Commit

Permalink
fix: Update types to support all possible react component return valu…
Browse files Browse the repository at this point in the history
…es (#1272)

* Update types to support all possible react component return values

* Update type test types
  • Loading branch information
trappar authored Feb 1, 2024
1 parent 4509fb6 commit 55e79c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export type RenderResult<
maxLength?: number,
options?: prettyFormat.OptionsReceived,
) => void
rerender: (ui: React.ReactElement) => void
rerender: (ui: React.ReactNode) => void
unmount: () => void
asFragment: () => DocumentFragment
} & {[P in keyof Q]: BoundFunction<Q[P]>}
Expand Down Expand Up @@ -90,7 +90,7 @@ export interface RenderOptions<
*
* @see https://testing-library.com/docs/react-testing-library/api/#wrapper
*/
wrapper?: React.JSXElementConstructor<{children: React.ReactElement}>
wrapper?: React.JSXElementConstructor<{children: React.ReactNode}>
}

type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
Expand All @@ -103,11 +103,11 @@ export function render<
Container extends Element | DocumentFragment = HTMLElement,
BaseElement extends Element | DocumentFragment = Container,
>(
ui: React.ReactElement,
ui: React.ReactNode,
options: RenderOptions<Q, Container, BaseElement>,
): RenderResult<Q, Container, BaseElement>
export function render(
ui: React.ReactElement,
ui: React.ReactNode,
options?: Omit<RenderOptions, 'queries'>,
): RenderResult

Expand Down
8 changes: 4 additions & 4 deletions types/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,18 @@ export function testQueries() {
}

export function wrappedRender(
ui: React.ReactElement,
ui: React.ReactNode,
options?: pure.RenderOptions,
) {
const Wrapper = ({children}: {children: React.ReactElement}): JSX.Element => {
const Wrapper = ({children}: {children: React.ReactNode}): JSX.Element => {
return <div>{children}</div>
}

return pure.render(ui, {wrapper: Wrapper, ...options})
}

export function wrappedRenderB(
ui: React.ReactElement,
ui: React.ReactNode,
options?: pure.RenderOptions,
) {
const Wrapper: React.FunctionComponent<{children?: React.ReactNode}> = ({
Expand All @@ -147,7 +147,7 @@ export function wrappedRenderB(
}

export function wrappedRenderC(
ui: React.ReactElement,
ui: React.ReactNode,
options?: pure.RenderOptions,
) {
interface AppWrapperProps {
Expand Down

0 comments on commit 55e79c2

Please sign in to comment.