Skip to content

[BUG] React component tests throw type error when passing null/undefined to component #29028

@bethmaloney

Description

@bethmaloney

System info

  • Playwright Version: [v1.41.0]
  • Operating System: [Windows 11]
  • Browser: [Chromium,]
  • Other info: Error did not occur in v1.40.1

Source code

Component

export const TestComponent = ({ value }: { value?: number }) => {
  return <div />;
};

Playwright test

test("PW Test", async ({ mount }) => {
  const component = await mount(<TestComponent value={undefined} />);
});

Steps

  • Run the test

Expected

Test should run and end successfully

Actual

Type error is thrown TypeError: Cannot read properties of undefined (reading '__pw_component_marker')

Running 1 test using 1 worker
  1) [chromium] › src\components\TestComponent.e2e.test.tsx:76:1 › PW Test ───────────

    Error: TypeError: Cannot read properties of undefined (reading '__pw_component_marker')

        at isComponent (http://localhost:3100/assets/index-bb8865af.js:191147:20)
        at __resolveProps (http://localhost:3100/assets/index-bb8865af.js:191188:14)
        at __pwResolveComponent (http://localhost:3100/assets/index-bb8865af.js:191178:11)
        at async window.playwrightMount (http://localhost:3100/assets/index-bb8865af.js:191243:3)
        at async eval (eval at evaluate (:226:30), <anonymous>:24:5)
        at async <anonymous>:252:30
        at isComponent (d:\test-repo\http:\localhost:3100\assets\index-bb8865af.js:191147:20)
        at __resolveProps (d:\test-repo\http:\localhost:3100\assets\index-bb8865af.js:191188:14)
        at __pwResolveComponent (d:\test-repo\http:\localhost:3100\assets\index-bb8865af.js:191178:11)
        at async window.playwrightMount (d:\test-repo\http:\localhost:3100\assets\index-bb8865af.js:191243:3)
        at async eval (d:\test-repo\eval at evaluate (:226:30), <anonymous>:24:5)
        at d:\test-repo\async <anonymous>:252:30
        at mount (d:\test-repo\node_modules\@playwright\experimental-ct-core\lib\mount.js:49:35)
        at d:\test-repo\src\components\TestComponent.e2e.test.tsx:77:27

  1 failed
    [chromium] › src\components\TestComponent.e2e.test.tsx:76:1 › PW Test ────────────

Additional Information

This also occurs for null values.

Omitting the undefined value as below and the test runs successfully

test("PW Test", async ({ mount }) => {
  const component = await mount(<TestComponent />);
});

Not sure if it's related to #29027

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions