Skip to content

[BUG] can't mount React component which takes another component as a prop in component test #18481

Description

@Hives

Context:

  • Playwright Version: 1.25.2 (experimental-ct-react)
  • Operating System: Ubuntu
  • Node.js version: 16.18.0
  • Browser: All

I've got a React component which takes another component as a prop, and I'm getting an error when I try to render this in Playwright. Here's a simplified example:

// in MyComponent.jsx

export const MyComponent = ({ SubComponent }) => {
  return (
    <div>
      <SubComponent />
    </div>
  );
};
// in MyComponent.playwright.spec.js

import { expect, test } from '@playwright/experimental-ct-react';
import { MyComponent } from './MyComponent';

const TestSubComponent = () => <p>Hello</p>;

test.describe('My Component', () => {
  test('it should render', async ({ mount, page }) => {
    const component = await mount(
      <MyComponent SubComponent={TestSubComponent} />
    );
    await expect(component).toContainText('Hello');
  });
});

My expectation is that this test should pass as it should render the SubComponent inside MyComponent. But what happens is that it fails with an error:


    undefined: Error: Minified React error #152; visit https://reactjs.org/docs/error-decoder.html?invariant=152&args[]=Component for the full message or use the non-minified dev environment for full errors and additional helpful warnings.

       6 | test.describe('My Component', () => {
       7 |   test('it should render', async ({ mount, page }) => {
    >  8 |     const component = await mount(
         |                             ^
       9 |       <MyComponent SubComponent={TestSubComponent} />
      10 |     );
      11 |     await expect(component).toContainText('Hello');

The React error is minified so it's hard to tell what's gone wrong.

Is this a bug, or am I doing something wrong?

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