Skip to content

Can not find createPortal from React DOM #1356

@Myllaume

Description

@Myllaume
  • @testing-library/react version: 16.0.1
  • @testing-library/dom version: 10.4.0
  • Testing Framework and version: Jest v.29.4.3, with TypeScript
  • DOM Environment: Jest DOM: "jest-environment-jsdom": "^29.4.3",
  • Node version : v20.8.1
  • React version: 18.3.1

Relevant code or config:

Tested component:

import { createPortal } from 'react-dom';

const Header = () => {
  return createPortal(<div />, document.getElementById("header"));
};

Test:

beforeAll(() => {
  const portalEl = document.createElement('div');
  portalEl.id = 'header';
  document.body.appendChild(portalEl);
});

it('should render primary content', () => {
  const { queryByTestId } = render(
    <Header primaryContainer={<div data-testid="primary" />} />,
  );
  expect(queryByTestId('primary')).not.toBeNull();
});

What you did:

I execute tests and get error.

What happened:

    TS2305: Module '"react-dom"' has no exported member 'createPortal'.

    3 import { createPortal } from 'react-dom';
               ~~~~~~~~~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions