fix(ct): solid render array as child (#27849)
closes: https://github.com/microsoft/playwright/issues/27587#issuecomment-1762133376 related: https://github.com/microsoft/playwright/pull/27692 CC @dgozman Co-authored-by: sand4rt <mbr@mbrs-MacBook-Air.local>
This commit is contained in:
parent
96787d2626
commit
1a34b6d211
|
|
@ -73,28 +73,27 @@ async function __pwResolveComponent(component) {
|
||||||
await Promise.all(component.children.map(child => __pwResolveComponent(child)));
|
await Promise.all(component.children.map(child => __pwResolveComponent(child)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {JsxComponentChild} child
|
||||||
|
*/
|
||||||
function __pwCreateChild(child) {
|
function __pwCreateChild(child) {
|
||||||
return typeof child === 'string' ? child : __pwCreateComponent(child);
|
if (Array.isArray(child))
|
||||||
|
return child.map(grandChild => __pwCreateChild(grandChild));
|
||||||
|
if (isComponent(child))
|
||||||
|
return __pwCreateComponent(child);
|
||||||
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {JsxComponent} component
|
* @param {JsxComponent} component
|
||||||
*/
|
*/
|
||||||
function __pwCreateComponent(component) {
|
function __pwCreateComponent(component) {
|
||||||
if (typeof component !== 'object' || Array.isArray(component))
|
|
||||||
return component;
|
|
||||||
|
|
||||||
const componentFunc = __pwRegistry.get(component.type);
|
const componentFunc = __pwRegistry.get(component.type);
|
||||||
|
const children = component.children.map(child => __pwCreateChild(child)).filter(child => {
|
||||||
|
if (typeof child === 'string')
|
||||||
const children = component.children.reduce((/** @type {any[]} */ children, current) => {
|
return !!child.trim();
|
||||||
const child = __pwCreateChild(current);
|
return true;
|
||||||
if (Array.isArray(child))
|
});
|
||||||
return child.map(grandChild => __pwCreateChild(grandChild));
|
|
||||||
if (typeof child !== 'string' || !!child.trim())
|
|
||||||
children.push(child);
|
|
||||||
return children;
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
if (!componentFunc)
|
if (!componentFunc)
|
||||||
return __pwH(component.type, component.props, children);
|
return __pwH(component.type, component.props, children);
|
||||||
|
|
|
||||||
|
|
@ -49,9 +49,9 @@ test('render string as child', async ({ mount }) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('render array as child', async ({ mount }) => {
|
test('render array as child', async ({ mount }) => {
|
||||||
const component = await mount(<DefaultChildren>{[<h4>{[4]}</h4>,<p>2</p>]}</DefaultChildren>);
|
const component = await mount(<DefaultChildren>{[<h4>{[4]}</h4>,[[<p>[2,3]</p>]]]}</DefaultChildren>);
|
||||||
await expect(component.getByRole('heading', { level: 4 })).toHaveText('4');
|
await expect(component.getByRole('heading', { level: 4 })).toHaveText('4');
|
||||||
await expect(component.getByRole('paragraph')).toHaveText('2');
|
await expect(component.getByRole('paragraph')).toHaveText('[2,3]');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('render number as child', async ({ mount }) => {
|
test('render number as child', async ({ mount }) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue