Skip to content

Commit cde904c

Browse files
kentcdoddseps1lon
andauthored
fix(TS): make wrapper allow a simple function comp (testing-library#966)
Co-authored-by: eps1lon <[email protected]>
1 parent a218b63 commit cde904c

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export interface RenderOptions<
7070
*
7171
* @see https://testing-library.com/docs/react-testing-library/api/#wrapper
7272
*/
73-
wrapper?: React.ComponentType
73+
wrapper?: React.ComponentType<{children: React.ReactElement}>
7474
}
7575

7676
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>

types/test.tsx

+22
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,28 @@ export function testQueries() {
100100
)
101101
}
102102

103+
export function wrappedRender(
104+
ui: React.ReactElement,
105+
options?: pure.RenderOptions,
106+
) {
107+
const Wrapper = ({children}: {children: React.ReactElement}): JSX.Element => {
108+
return <div>{children}</div>
109+
}
110+
111+
return pure.render(ui, {wrapper: Wrapper, ...options})
112+
}
113+
114+
export function wrappedRenderB(
115+
ui: React.ReactElement,
116+
options?: pure.RenderOptions,
117+
) {
118+
const Wrapper: React.FunctionComponent = ({children}) => {
119+
return <div>{children}</div>
120+
}
121+
122+
return pure.render(ui, {wrapper: Wrapper, ...options})
123+
}
124+
103125
/*
104126
eslint
105127
testing-library/prefer-explicit-assert: "off",

0 commit comments

Comments
 (0)