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

Bug: Render Function Wrapper Typescript Issue #965

Closed
akashshyamdev opened this issue Sep 24, 2021 · 8 comments · Fixed by #966
Closed

Bug: Render Function Wrapper Typescript Issue #965

akashshyamdev opened this issue Sep 24, 2021 · 8 comments · Fixed by #966

Comments

@akashshyamdev
Copy link

  • @testing-library/react version: ^11.1.0
  • Testing Framework and version(JEST): ^26.6.0
  • Dom ENV: JS dom(default, no specific config)

Relevant code or config:

import { render as rtlRender, RenderOptions, screen } from '@testing-library/react';
import { createMemoryHistory } from 'history';
import React, { Component, ReactElement } from 'react';
import { Router } from 'react-router-dom';
import App from './App';

type DefaultOptions = Omit<RenderOptions, 'queries'> & { route: string };

const render = (ui: ReactElement, options?: DefaultOptions) => {
  const history = createMemoryHistory({ initialEntries: [options?.route || '/'] });

  const Wrapper = ({ children }: { children: ReactElement }) => {
    return <Router history={history}>{children}</Router>;
  };

  return rtlRender(ui, { wrapper: Wrapper, ...options });
};

test('renders to screen', () => {
  render(<App />);

  expect(screen.getByTestId('router')).toBeInTheDocument();
});

What happened:

This is a typescript error. check the screenshot below for the error:
Screenshot 2021-09-24 at 12 35 12

Problem description:

I believe the problem is coming from here:
Screenshot 2021-09-24 at 12 36 41

Suggested solution:

I believe that this can be solved easily by a simple change. I've changed the wrapper type from React.ComponentType to JSX.Element. Is this a bug or is this being done intentionally?

Screenshot 2021-09-24 at 12 37 32

@kentcdodds
Copy link
Member

I literally just ran into this myself. The proper fix should probably be: wrapper?: (props: {children: React.ReactNode}) => JSX.Element. I'll make a PR.

@akashshyamdev
Copy link
Author

akashshyamdev commented Sep 25, 2021

Thanks @kentcdodds 👍 . btw, I'm coming from your course and it's absolutely great! Are there any pending beginner friendly issues/tasks which I could work on?

@kentcdodds
Copy link
Member

Awesome! I'm afraid that I don't maintain this project anymore much so I can't really recommend something to you for this project. But Hactoberfest is coming soon. Maybe you'll find something there :)

@eps1lon eps1lon reopened this Sep 27, 2021
@eps1lon
Copy link
Member

eps1lon commented Sep 27, 2021

@all-contributors add @akashshyamdev for bug

@allcontributors
Copy link
Contributor

@eps1lon

I've put up a pull request to add @akashshyamdev! 🎉

@akashshyamdev
Copy link
Author

Thanks @eps1lon. btw, Are there any pending beginner friendly issues/tasks which I could work on?

@github-actions
Copy link

🎉 This issue has been resolved in version 12.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link

🎉 This issue has been resolved in version 13.0.0-alpha.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants