Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(TS): make wrapper allow a simple function comp #966

Merged
merged 7 commits into from Sep 27, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion types/index.d.ts
Expand Up @@ -70,7 +70,9 @@ export interface RenderOptions<
*
* @see https://testing-library.com/docs/react-testing-library/api/#wrapper
*/
wrapper?: React.ComponentType
wrapper?:
| React.ComponentType
| ((props: {children: React.ReactNode}) => JSX.Element)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me add a type test for this because the fix is simpler I believe.

Copy link
Member

@eps1lon eps1lon Sep 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implicit children strikes again (DefinitelyTyped/DefinitelyTyped#34237):

React.ComponentType includes React.FunctionComponent which means the accepted props are { children?: React.ReactNode }. However, our Wrapper only accepts { children: React.ReactElement } props. So we could render <Wrapper>Some Child</Wrapper> which may not be implemented by the custom Wrapper component because now it receives { children: string }.

The proposed fix would not have fixed the linked issue (npm typecheck fails on ffa2221). dc03098 fixes the linked issue.

}

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