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

[BUG] Experimental CT: Svelte named Slots #15820

Closed
aMediocreDad opened this issue Jul 20, 2022 · 6 comments · Fixed by #17943
Closed

[BUG] Experimental CT: Svelte named Slots #15820

aMediocreDad opened this issue Jul 20, 2022 · 6 comments · Fixed by #17943
Assignees

Comments

@aMediocreDad
Copy link

Context:

  • Playwright Version: experimental-ct-svelte": 1.23.4
  • Operating System: Mac / Linux
  • Node.js version: 16.14.2 / 18.5.0
  • Browser: All
  • Extra: *

Code Snippet

Help us help you! Put down a short code snippet that illustrates your bug and
that we can run and debug locally. For example:

Reproduction: https://github.com/aMediocreDad/playwright-svelte-slots-repro

import { test, expect } from "@playwright/experimental-ct-svelte";

import Component from "./slot-example.svelte";

test("Named Slots", async ({ mount }) => {
	const component = await mount(Component, {
		props: {
			title: "Named Slots",
		},
		// This should work
		slots: {
			text: "Hello World",
		},
	});

	const title = component.locator("h1");

	await expect(title).toHaveText("Named Slots");

	const text = component.locator("p");

	// Yet, this fails
	await expect(text).toContainText("Hello World");
});

Describe the bug

While this is experimental the FAQ indicates that you can pass (text) to named slots when mounting the Svelte component.

This seems to be wrong. It would, however, be a desirable feature.

@sand4rt
Copy link
Collaborator

sand4rt commented Aug 3, 2022

related to: sveltejs/svelte#2588

@aMediocreDad
Copy link
Author

related to: sveltejs/svelte#2588

I was under the impression that Playwright had some custom code that did this. Injecting slots programmatically when mounting Svelte components has never been a feature in Svelte 3. It does, however, look like it is possible when using an editor like VS Code and the Svelte LSP, this because of an internal handler for the typing of the component that unfortunately has to be exposed.

@bhvngt
Copy link

bhvngt commented Aug 17, 2022

I stumble upon this while playing around with component testing for my svelte components. As @aMediocreDad said, seems like passing of slots (default or named) is not working out of the box.

@aMediocreDad Did you manage to make it work for your use case by following sveltejs/svelte#2588. Code there does not seem to work for me.

@aMediocreDad
Copy link
Author

@aMediocreDad Did you manage to make it work for your use case by following sveltejs/svelte#2588. Code there does not seem to work for me.

No, I have not tried using those solutions. We use the same solutions we do for Storybook, which is using a svelte component that wraps the one being tested populating the slot with relevant parameters exposed through props.

@bhvngt
Copy link

bhvngt commented Oct 11, 2022

Thanks @sand4rt for addressing this issue. The included test passes text content to the slot. Is it also possible to pass components to slots?

@sand4rt
Copy link
Collaborator

sand4rt commented Oct 11, 2022

@bhvngt lets track that in: #15900

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants