mirror of
https://github.com/microsoft/playwright.git
synced 2024-10-26 21:33:38 +03:00
fix(ct): react render array as child (#27692)
Signed-off-by: Sander <info@mesander.com> Co-authored-by: Dmitry Gozman <dgozman@gmail.com> Co-authored-by: mbr <mbr@mbrs-MacBook-Air.local>
This commit is contained in:
parent
462e70ab82
commit
3313381040
@ -76,23 +76,27 @@ async function __pwResolveComponent(component) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {JsxComponent | JsxComponentChild} component
|
||||
* @param {JsxComponentChild} child
|
||||
*/
|
||||
function __renderChild(child) {
|
||||
if (Array.isArray(child))
|
||||
return child.map(grandChild => __renderChild(grandChild));
|
||||
if (isComponent(child))
|
||||
return __pwRender(child);
|
||||
return child;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {JsxComponent} component
|
||||
*/
|
||||
function __pwRender(component) {
|
||||
if (!isComponent(component))
|
||||
return component;
|
||||
|
||||
const componentFunc = __pwRegistry.get(component.type);
|
||||
|
||||
return __pwReact.createElement(componentFunc || component.type, component.props, ...component.children.map(child => {
|
||||
if (typeof child === 'string')
|
||||
return child;
|
||||
return __pwRender(child);
|
||||
}).filter(child => {
|
||||
const children = component.children.map(child => __renderChild(child)).filter(child => {
|
||||
if (typeof child === 'string')
|
||||
return !!child.trim();
|
||||
return true;
|
||||
}));
|
||||
});
|
||||
return __pwReact.createElement(componentFunc || component.type, component.props, children);
|
||||
}
|
||||
|
||||
window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
||||
|
@ -75,23 +75,27 @@ async function __pwResolveComponent(component) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {JsxComponent | JsxComponentChild} component
|
||||
* @param {JsxComponentChild} child
|
||||
*/
|
||||
function __renderChild(child) {
|
||||
if (Array.isArray(child))
|
||||
return child.map(grandChild => __renderChild(grandChild));
|
||||
if (isComponent(child))
|
||||
return __pwRender(child);
|
||||
return child;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {JsxComponent} component
|
||||
*/
|
||||
function __pwRender(component) {
|
||||
if (!isComponent(component))
|
||||
return component;
|
||||
|
||||
const componentFunc = __pwRegistry.get(component.type);
|
||||
|
||||
return __pwReact.createElement(componentFunc || component.type, component.props, ...component.children.map(child => {
|
||||
if (typeof child === 'string')
|
||||
return child;
|
||||
return __pwRender(child);
|
||||
}).filter(child => {
|
||||
const children = component.children.map(child => __renderChild(child)).filter(child => {
|
||||
if (typeof child === 'string')
|
||||
return !!child.trim();
|
||||
return true;
|
||||
}));
|
||||
});
|
||||
return __pwReact.createElement(componentFunc || component.type, component.props, children);
|
||||
}
|
||||
|
||||
window.playwrightMount = async (component, rootElement, hooksConfig) => {
|
||||
|
@ -49,8 +49,9 @@ test('render string as child', async ({ mount }) => {
|
||||
});
|
||||
|
||||
test('render array as child', async ({ mount }) => {
|
||||
const component = await mount(<DefaultChildren>{[4,2]}</DefaultChildren>);
|
||||
await expect(component).toContainText('42');
|
||||
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('paragraph')).toHaveText('[2,3]');
|
||||
});
|
||||
|
||||
test('render number as child', async ({ mount }) => {
|
||||
|
@ -49,8 +49,9 @@ test('render string as child', async ({ mount }) => {
|
||||
});
|
||||
|
||||
test('render array as child', async ({ mount }) => {
|
||||
const component = await mount(<DefaultChildren>{[4,2]}</DefaultChildren>);
|
||||
await expect(component).toContainText('42');
|
||||
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('paragraph')).toHaveText('[2,3]');
|
||||
});
|
||||
|
||||
test('render number as child', async ({ mount }) => {
|
||||
|
Loading…
Reference in New Issue
Block a user