diff --git a/packages/playwright-ct-react/registerSource.mjs b/packages/playwright-ct-react/registerSource.mjs index 5c8c97f4f7..ff26e17c9c 100644 --- a/packages/playwright-ct-react/registerSource.mjs +++ b/packages/playwright-ct-react/registerSource.mjs @@ -36,9 +36,11 @@ export function register(components) { /** * @param {Component} component - * @returns {JSX.Element} */ function render(component) { + if (typeof component !== 'object' || Array.isArray(component)) + return component; + let componentFunc = registry.get(component.type); if (!componentFunc) { // Lookup by shorthand. diff --git a/packages/playwright-ct-solid/registerSource.mjs b/packages/playwright-ct-solid/registerSource.mjs index cb71f0061e..d7194137e3 100644 --- a/packages/playwright-ct-solid/registerSource.mjs +++ b/packages/playwright-ct-solid/registerSource.mjs @@ -42,7 +42,7 @@ function createChild(child) { * @param {Component} component */ function createComponent(component) { - if (typeof component === 'string') + if (typeof component !== 'object' || Array.isArray(component)) return component; let Component = registry.get(component.type); diff --git a/packages/playwright-test/types/component.d.ts b/packages/playwright-test/types/component.d.ts index 22f29cc2a8..41ce974c94 100644 --- a/packages/playwright-test/types/component.d.ts +++ b/packages/playwright-test/types/component.d.ts @@ -34,7 +34,7 @@ export type ObjectComponent = { options?: MountOptions }; -export type Component = JsxComponent | ObjectComponent; +export type Component = JsxComponent | ObjectComponent | number | string | Array; declare global { interface Window { diff --git a/tests/components/ct-react-vite/tests/children.spec.tsx b/tests/components/ct-react-vite/tests/children.spec.tsx index ca68979c95..d676315253 100644 --- a/tests/components/ct-react-vite/tests/children.spec.tsx +++ b/tests/components/ct-react-vite/tests/children.spec.tsx @@ -42,3 +42,18 @@ test('render named children', async ({ mount }) => { await expect(component).toContainText('Main Content'); await expect(component).toContainText('Footer'); }); + +test('render string as child', async ({ mount }) => { + const component = await mount({'string'}); + await expect(component).toContainText('string'); +}); + +test('render array as child', async ({ mount }) => { + const component = await mount({[4,2]}); + await expect(component).toContainText('42'); +}); + +test('render number as child', async ({ mount }) => { + const component = await mount({1337}); + await expect(component).toContainText('1337'); +}); diff --git a/tests/components/ct-react/tests/children.spec.tsx b/tests/components/ct-react/tests/children.spec.tsx index ca68979c95..d676315253 100644 --- a/tests/components/ct-react/tests/children.spec.tsx +++ b/tests/components/ct-react/tests/children.spec.tsx @@ -42,3 +42,18 @@ test('render named children', async ({ mount }) => { await expect(component).toContainText('Main Content'); await expect(component).toContainText('Footer'); }); + +test('render string as child', async ({ mount }) => { + const component = await mount({'string'}); + await expect(component).toContainText('string'); +}); + +test('render array as child', async ({ mount }) => { + const component = await mount({[4,2]}); + await expect(component).toContainText('42'); +}); + +test('render number as child', async ({ mount }) => { + const component = await mount({1337}); + await expect(component).toContainText('1337'); +}); diff --git a/tests/components/ct-solid/tests/children.spec.tsx b/tests/components/ct-solid/tests/children.spec.tsx index 859539c92c..8632415ecb 100644 --- a/tests/components/ct-solid/tests/children.spec.tsx +++ b/tests/components/ct-solid/tests/children.spec.tsx @@ -42,3 +42,18 @@ test('render named children', async ({ mount }) => { await expect(component).toContainText('Main Content'); await expect(component).toContainText('Footer'); }); + +test('render string as child', async ({ mount }) => { + const component = await mount({'string'}); + await expect(component).toContainText('string'); +}); + +test('render array as child', async ({ mount }) => { + const component = await mount({[4,2]}); + await expect(component).toContainText('42'); +}); + +test('render number as child', async ({ mount }) => { + const component = await mount({1337}); + await expect(component).toContainText('1337'); +});