Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore(vue): allow adding events in jsx templates (#12746)

Pavel Feldman6b324d378008
diff --git a/packages/playwright-ct-vue/register.mjs b/packages/playwright-ct-vue/register.mjs
index 8b1e40afd4..bccabf3543 100644
--- a/packages/playwright-ct-vue/register.mjs
+++ b/packages/playwright-ct-vue/register.mjs
@@ -32,6 +32,7 @@ function render(component) {
if (typeof component === 'string')
return component;
const componentFunc = registry.get(component.type) || component.type;
+ const isVueComponent = componentFunc !== component.type;
const children = [];
const slots = {};
@@ -50,10 +51,15 @@ function render(component) {
}
for (const [key, value] of Object.entries(component.props)) {
- if (key.startsWith('v-on:'))
- listeners[key.substring('v-on:'.length)] = value;
- else
+ if (key.startsWith('v-on:')) {
+ const event = key.substring('v-on:'.length);
+ if (isVueComponent)
+ listeners[event] = value;
+ else
+ props[`on${event[0].toUpperCase()}${event.substring(1)}`] = value;
+ } else {
props[key] = value;
+ }
}
}
diff --git a/tests-components/ct-vue-vite/src/notation-jsx.spec.tsx b/tests-components/ct-vue-vite/src/notation-jsx.spec.tsx
index ad313bb9f0..0db137e400 100644
--- a/tests-components/ct-vue-vite/src/notation-jsx.spec.tsx
+++ b/tests-components/ct-vue-vite/src/notation-jsx.spec.tsx
@@ -51,3 +51,12 @@ test('named slots should work', async ({ mount }) => {
await expect(component).toContainText('Main Content')
await expect(component).toContainText('Footer')
})
+
+test('slot should emit events', async ({ mount }) => {
+ let clickFired = false;
+ const component = await mount(<DefaultSlot>
+ <span v-on:click={() => clickFired = true}>Main Content</span>
+ </DefaultSlot>);
+ await component.locator('text=Main Content').click();
+ expect(clickFired).toBeTruthy();
+})