diff --git a/packages/playwright-ct-react/registerSource.mjs b/packages/playwright-ct-react/registerSource.mjs index 813ff4d88b..74d16cf5c1 100644 --- a/packages/playwright-ct-react/registerSource.mjs +++ b/packages/playwright-ct-react/registerSource.mjs @@ -32,6 +32,14 @@ function isJsxComponent(component) { return typeof component === 'object' && component && component.__pw_type === 'jsx'; } +/** + * @param {any} type + * @returns type is Playwright's mock JSX.Fragment + */ +function isJsxFragment(type) { + return typeof type === 'object' && type?.__pw_jsx_fragment; +} + /** * Turns the Playwright representation of JSX (see jsx-runtime.js) into React.createElement calls. * @param {any} value @@ -41,7 +49,7 @@ function __pwRender(value) { if (isJsxComponent(v)) { const component = v; let type = component.type; - if (type && type.__pw_jsx_fragment) + if (isJsxFragment(type)) type = __pwReact.Fragment; const props = component.props ? __pwRender(component.props) : {}; const key = component.key ? __pwRender(component.key) : undefined;