Skip to content

Bug: Render Function Wrapper Typescript Issue #965

Closed
@akashshyamdev

Description

@akashshyamdev
  • @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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions