Skip to content

Commit 7f53b56

Browse files
authored
fix(render): Don't reject wrapper types based on statics (testing-library#973)
1 parent cde904c commit 7f53b56

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
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<{children: React.ReactElement}>
73+
wrapper?: React.JSXElementConstructor<{children: React.ReactElement}>
7474
}
7575

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

types/test.tsx

+20-1
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,32 @@ export function wrappedRenderB(
115115
ui: React.ReactElement,
116116
options?: pure.RenderOptions,
117117
) {
118-
const Wrapper: React.FunctionComponent = ({children}) => {
118+
const Wrapper: React.FunctionComponent<{children?: React.ReactNode}> = ({
119+
children,
120+
}) => {
119121
return <div>{children}</div>
120122
}
121123

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

127+
export function wrappedRenderC(
128+
ui: React.ReactElement,
129+
options?: pure.RenderOptions,
130+
) {
131+
interface AppWrapperProps {
132+
userProviderProps?: {user: string}
133+
}
134+
const AppWrapperProps: React.FunctionComponent<AppWrapperProps> = ({
135+
children,
136+
userProviderProps = {user: 'TypeScript'},
137+
}) => {
138+
return <div data-testid={userProviderProps.user}>{children}</div>
139+
}
140+
141+
return pure.render(ui, {wrapper: AppWrapperProps, ...options})
142+
}
143+
125144
/*
126145
eslint
127146
testing-library/prefer-explicit-assert: "off",

0 commit comments

Comments
 (0)