From bb1ae4c4ece2316a9e4f0c448021c57d654544e7 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Wed, 2 Oct 2024 10:35:06 +0200 Subject: [PATCH] move to function --- packages/playwright-ct-react/registerSource.mjs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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;