Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ct): vue render array as slot #27851

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/playwright-ct-vue/registerSource.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@ const __pwAllListeners = new Map();

/**
* @param {JsxComponentChild} child
* @returns {import('vue').VNode | string}
*/
function __pwCreateChild(child) {
return typeof child === 'string' ? child : __pwCreateWrapper(child);
if (Array.isArray(child))
return child.map(grandChild => __pwCreateChild(grandChild));
if (isComponent(child))
return __pwCreateWrapper(child);
return child;
}

/**
Expand Down Expand Up @@ -133,9 +136,6 @@ function __pwSlotToFunction(slot) {
* @param {Component} component
*/
function __pwCreateComponent(component) {
if (typeof component === 'string')
return component;

let componentFunc = __pwRegistry.get(component.type);
componentFunc = componentFunc || component.type;

Expand Down
6 changes: 5 additions & 1 deletion packages/playwright-ct-vue2/registerSource.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ async function __pwResolveComponent(component) {
* @param {Component | JsxComponentChild} child
*/
function __pwCreateChild(child) {
return typeof child === 'string' ? child : __pwCreateWrapper(child);
if (Array.isArray(child))
return child.map(grandChild => __pwCreateChild(grandChild));
if (isComponent(child))
return __pwCreateWrapper(child);
return child;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/components/ct-vue-cli/tests/slots/slots.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ test('render a component with a named slot', async ({ mount }) => {
await expect(component).toContainText('Main Content');
await expect(component).toContainText('Footer');
});

test('render array as child', async ({ mount }) => {
const component = await mount(<DefaultSlot>{[<h4>{[4]}</h4>,[[<p>[2,3]</p>]]]}</DefaultSlot>);
await expect(component.getByRole('heading', { level: 4 })).toHaveText('4');
await expect(component.getByRole('paragraph')).toHaveText('[2,3]');
});
6 changes: 6 additions & 0 deletions tests/components/ct-vue-vite/tests/slots/slots.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ test('render a component with a named slot', async ({ mount }) => {
await expect(component).toContainText('Main Content');
await expect(component).toContainText('Footer');
});

test('render array as child', async ({ mount }) => {
const component = await mount(<DefaultSlot>{[<h4>{[4]}</h4>,[[<p>[2,3]</p>]]]}</DefaultSlot>);
await expect(component.getByRole('heading', { level: 4 })).toHaveText('4');
await expect(component.getByRole('paragraph')).toHaveText('[2,3]');
});
6 changes: 6 additions & 0 deletions tests/components/ct-vue2-cli/tests/slots/slots.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ test('render a component with a named slot', async ({ mount }) => {
await expect(component).toContainText('Main Content');
await expect(component).toContainText('Footer');
});

test('render array as child', async ({ mount }) => {
const component = await mount(<DefaultSlot>{[<h4>{[4]}</h4>,[[<p>[2,3]</p>]]]}</DefaultSlot>);
await expect(component.getByRole('heading', { level: 4 })).toHaveText('4');
await expect(component.getByRole('paragraph')).toHaveText('[2,3]');
});
Loading