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

Wrapper type breaks types with props other than children #970

Closed
cfbender opened this issue Sep 27, 2021 · 3 comments · Fixed by #973
Closed

Wrapper type breaks types with props other than children #970

cfbender opened this issue Sep 27, 2021 · 3 comments · Fixed by #973
Labels
bug Something isn't working TypeScript Related to TypeScript. Note: only certain maintainers handle TypeScript labeled issues.

Comments

@cfbender
Copy link

cfbender commented Sep 27, 2021

  • @testing-library/react version: 12.1.1
  • Testing Framework and version: jest @ 27.2.2
  • DOM Environment: 5.14.1

Relevant code or config:

type AppWrapperProps = {
  userProviderProps?: UserProviderProps
}

export const AppWrapper: React.FC<AppWrapperProps> = ({
  children,
  userProviderProps = { user: mockUser },
}) => (
  <UserProvider {...userProviderProps}>
...

What you did:

Upgraded @testing-library/react to 12.1.1

What happened:

Type for wrapper broken in #966

Reproduction:

Use wrapper component that has some props that can be passed

Problem description:

The type being inflexible (only allowing children) means that the wrapper can't take props if used anywhere else

Suggested solution:

Something like wrapper?: React.ComponentType<React.PropsWithChildren>

@eps1lon
Copy link
Member

eps1lon commented Sep 28, 2021

Could you provide a full repro how AppWrapper receives all the props with your custom render method?

@cfbender
Copy link
Author

Sure thing!

we are wanting to sometimes use it as such:

type AppWrapperProps = {
  userProviderProps?: UserProviderProps
}

export const AppWrapper: React.FC<AppWrapperProps> = ({
  children,
  userProviderProps = { user: mockUser },
}) => (
  <UserProvider {...userProviderProps}>
    {children}
  </UserProvider>
)

...

    render(<Page {...defaultPageProps.props} />, {
      wrapper: AppWrapper,
    })
    
    // OR
    
    render(
      <AppWrapper userProviderProps={{ ...user }}>
        <Page {...defaultPageProps.props} />
      </AppWrapper>
    )

this gives us the ability to use the same component in multiple ways and overriding some props in the provider

@bfaulk96
Copy link

bfaulk96 commented Sep 28, 2021

Came here with a very similar issue. The latest release caused new TS type mismatch errors for wrapper.
Temporarily using as RenderOptions['wrapper'] to fix, but obviously this isn't ideal

sabertazimi added a commit to sabertazimi/blog that referenced this issue Oct 1, 2021
`@testing-library/react` introduced new type definition for `wrapper`
in PR testing-library/react-testing-library#966,
then released it in `v12.1.1`.

issue testing-library/react-testing-library#970
github-actions bot added a commit to sabertazimi/blog that referenced this issue Oct 1, 2021
`@testing-library/react` introduced new type definition for `wrapper`
in PR testing-library/react-testing-library#966,
then released it in `v12.1.1`.

issue testing-library/react-testing-library#970 5420890
@eps1lon eps1lon added bug Something isn't working TypeScript Related to TypeScript. Note: only certain maintainers handle TypeScript labeled issues. labels Oct 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working TypeScript Related to TypeScript. Note: only certain maintainers handle TypeScript labeled issues.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants