Skip to content

Commit 061e9fd

Browse files
committed
feat: default slot
1 parent 7669d3a commit 061e9fd

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

Diff for: ct-web-lit/src/tests.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ test('emit an submit event when the button is clicked', async ({ mount }) => {
7676
expect(messages).toEqual(['hello']);
7777
});
7878

79-
test.fixme('render a default slot', async ({ mount }) => {
79+
test('render a default slot', async ({ mount }) => {
8080
const component = await mount(DefaultSlot, {
8181
slots: {
8282
default: '<strong>Main Content</strong>',

Diff for: ct-web/src/components/DefaultSlot.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
export class DefaultSlot extends HTMLElement {
22
constructor() {
33
super();
4+
this.innerHTML = `
5+
<div>
6+
<h1>Welcome!</h1>
7+
<main><slot /></main>
8+
<footer>Thanks for visiting.</footer>
9+
</div>
10+
`;
411
}
512
}
613

Diff for: ct-web/src/tests.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ test('emit an submit event when the button is clicked', async ({ mount }) => {
7676
expect(messages).toEqual(['hello']);
7777
});
7878

79-
test.fixme('render a default slot', async ({ mount }) => {
79+
test('render a default slot', async ({ mount }) => {
8080
const component = await mount(DefaultSlot, {
8181
slots: {
8282
default: '<strong>Main Content</strong>',

Diff for: playwright-ct-web/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sand4rt/experimental-ct-web",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"description": "Playwright Component Testing for Web Components",
55
"homepage": "https://playwright.dev",
66
"engines": {

Diff for: playwright-ct-web/registerSource.mjs

+8-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,14 @@ function createComponent(component) {
4545
for (const [key, listener] of Object.entries(component.options?.on || {}))
4646
webComponent.addEventListener(key, event => listener(/** @type {CustomEvent} */ (event).detail));
4747

48-
if (component.options?.slots)
49-
throw new Error('slots are not yet supported');
48+
for (const [key, value] of Object.entries(component.options?.slots || {})) {
49+
const slot = document.createRange().createContextualFragment(value);
50+
51+
if (key !== 'default')
52+
throw new Error('named slots are not yet supported');
53+
54+
webComponent.appendChild(slot);
55+
}
5056

5157
for (const [key, value] of Object.entries(component.options?.props || {}))
5258
webComponent[key] = value;

0 commit comments

Comments
 (0)