Skip to content

Commit

Permalink
fix(TS): make wrapper allow a simple function comp (#966)
Browse files Browse the repository at this point in the history
Co-authored-by: eps1lon <silbermann.sebastian@gmail.com>
  • Loading branch information
kentcdodds and eps1lon committed Sep 27, 2021
1 parent a218b63 commit cde904c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion types/index.d.ts
Expand Up @@ -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<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
Expand Down
22 changes: 22 additions & 0 deletions types/test.tsx
Expand Up @@ -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 <div>{children}</div>
}

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

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

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

/*
eslint
testing-library/prefer-explicit-assert: "off",
Expand Down

0 comments on commit cde904c

Please sign in to comment.