From cde904cd161782090d7ab7256bcb9b13e771d0ea Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Mon, 27 Sep 2021 06:39:57 -0600 Subject: [PATCH] fix(TS): make wrapper allow a simple function comp (#966) Co-authored-by: eps1lon --- types/index.d.ts | 2 +- types/test.tsx | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index 663e6280..3baf7b5e 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -70,7 +70,7 @@ export interface RenderOptions< * * @see https://testing-library.com/docs/react-testing-library/api/#wrapper */ - wrapper?: React.ComponentType + wrapper?: React.ComponentType<{children: React.ReactElement}> } type Omit = Pick> diff --git a/types/test.tsx b/types/test.tsx index 239caed6..7c45eaae 100644 --- a/types/test.tsx +++ b/types/test.tsx @@ -100,6 +100,28 @@ export function testQueries() { ) } +export function wrappedRender( + ui: React.ReactElement, + options?: pure.RenderOptions, +) { + const Wrapper = ({children}: {children: React.ReactElement}): JSX.Element => { + return
{children}
+ } + + return pure.render(ui, {wrapper: Wrapper, ...options}) +} + +export function wrappedRenderB( + ui: React.ReactElement, + options?: pure.RenderOptions, +) { + const Wrapper: React.FunctionComponent = ({children}) => { + return
{children}
+ } + + return pure.render(ui, {wrapper: Wrapper, ...options}) +} + /* eslint testing-library/prefer-explicit-assert: "off",