fix: fixed event reassignment on update and removed slot tests for v4

This commit is contained in:
Marcin Wiśniowski 2025-02-24 17:26:20 +01:00
parent 642b074ac3
commit 1a47fc3af5
2 changed files with 6 additions and 25 deletions

View file

@ -92,6 +92,9 @@ window.playwrightMount = async (component, rootElement, hooksConfig) => {
for (const hook of window.__pw_hooks_after_mount || [])
await hook({ hooksConfig, svelteComponent });
for (const [key, listener] of Object.entries(component.on || {}))
svelteComponent.$on(key, event => listener(event.detail));
};
window.playwrightUnmount = async rootElement => {
@ -111,4 +114,7 @@ window.playwrightUpdate = async (rootElement, component) => {
throw new Error('Component was not mounted');
svelteComponent.$set(extractParams(component));
for (const [key, listener] of Object.entries(component.on || {}))
svelteComponent.$on(key, event => listener(event.detail));
};

View file

@ -1,25 +0,0 @@
import { test, expect } from '@playwright/experimental-ct-svelte';
import DefaultSlot from '@/components/DefaultSlot.svelte';
import NamedSlots from '@/components/NamedSlots.svelte';
test('render a default slot', async ({ mount }) => {
const component = await mount(DefaultSlot, {
slots: {
default: 'Main Content',
},
});
await expect(component).toContainText('Main Content');
});
test('render a component with a named slot', async ({ mount }) => {
const component = await mount(NamedSlots, {
slots: {
header: 'Header',
main: 'Main Content',
footer: 'Footer',
},
});
await expect(component).toContainText('Header');
await expect(component).toContainText('Main Content');
await expect(component).toContainText('Footer');
});