mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(ct): solid and react JS as child (#20125)
This commit is contained in:
parent
0b300f455c
commit
d58d833daf
@ -36,9 +36,11 @@ export function register(components) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Component} component
|
* @param {Component} component
|
||||||
* @returns {JSX.Element}
|
|
||||||
*/
|
*/
|
||||||
function render(component) {
|
function render(component) {
|
||||||
|
if (typeof component !== 'object' || Array.isArray(component))
|
||||||
|
return component;
|
||||||
|
|
||||||
let componentFunc = registry.get(component.type);
|
let componentFunc = registry.get(component.type);
|
||||||
if (!componentFunc) {
|
if (!componentFunc) {
|
||||||
// Lookup by shorthand.
|
// Lookup by shorthand.
|
||||||
|
|||||||
@ -42,7 +42,7 @@ function createChild(child) {
|
|||||||
* @param {Component} component
|
* @param {Component} component
|
||||||
*/
|
*/
|
||||||
function createComponent(component) {
|
function createComponent(component) {
|
||||||
if (typeof component === 'string')
|
if (typeof component !== 'object' || Array.isArray(component))
|
||||||
return component;
|
return component;
|
||||||
|
|
||||||
let Component = registry.get(component.type);
|
let Component = registry.get(component.type);
|
||||||
|
|||||||
@ -34,7 +34,7 @@ export type ObjectComponent = {
|
|||||||
options?: MountOptions
|
options?: MountOptions
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Component = JsxComponent | ObjectComponent;
|
export type Component = JsxComponent | ObjectComponent | number | string | Array<any>;
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
|
|||||||
@ -42,3 +42,18 @@ test('render named children', async ({ mount }) => {
|
|||||||
await expect(component).toContainText('Main Content');
|
await expect(component).toContainText('Main Content');
|
||||||
await expect(component).toContainText('Footer');
|
await expect(component).toContainText('Footer');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('render string as child', async ({ mount }) => {
|
||||||
|
const component = await mount(<DefaultChildren>{'string'}</DefaultChildren>);
|
||||||
|
await expect(component).toContainText('string');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('render array as child', async ({ mount }) => {
|
||||||
|
const component = await mount(<DefaultChildren>{[4,2]}</DefaultChildren>);
|
||||||
|
await expect(component).toContainText('42');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('render number as child', async ({ mount }) => {
|
||||||
|
const component = await mount(<DefaultChildren>{1337}</DefaultChildren>);
|
||||||
|
await expect(component).toContainText('1337');
|
||||||
|
});
|
||||||
|
|||||||
@ -42,3 +42,18 @@ test('render named children', async ({ mount }) => {
|
|||||||
await expect(component).toContainText('Main Content');
|
await expect(component).toContainText('Main Content');
|
||||||
await expect(component).toContainText('Footer');
|
await expect(component).toContainText('Footer');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('render string as child', async ({ mount }) => {
|
||||||
|
const component = await mount(<DefaultChildren>{'string'}</DefaultChildren>);
|
||||||
|
await expect(component).toContainText('string');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('render array as child', async ({ mount }) => {
|
||||||
|
const component = await mount(<DefaultChildren>{[4,2]}</DefaultChildren>);
|
||||||
|
await expect(component).toContainText('42');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('render number as child', async ({ mount }) => {
|
||||||
|
const component = await mount(<DefaultChildren>{1337}</DefaultChildren>);
|
||||||
|
await expect(component).toContainText('1337');
|
||||||
|
});
|
||||||
|
|||||||
@ -42,3 +42,18 @@ test('render named children', async ({ mount }) => {
|
|||||||
await expect(component).toContainText('Main Content');
|
await expect(component).toContainText('Main Content');
|
||||||
await expect(component).toContainText('Footer');
|
await expect(component).toContainText('Footer');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('render string as child', async ({ mount }) => {
|
||||||
|
const component = await mount(<DefaultChildren>{'string'}</DefaultChildren>);
|
||||||
|
await expect(component).toContainText('string');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('render array as child', async ({ mount }) => {
|
||||||
|
const component = await mount(<DefaultChildren>{[4,2]}</DefaultChildren>);
|
||||||
|
await expect(component).toContainText('42');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('render number as child', async ({ mount }) => {
|
||||||
|
const component = await mount(<DefaultChildren>{1337}</DefaultChildren>);
|
||||||
|
await expect(component).toContainText('1337');
|
||||||
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user