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

Not imported Vue component does not mount #29914

Closed
1 task done
pbrzosko opened this issue Mar 12, 2024 · 3 comments
Closed
1 task done

Not imported Vue component does not mount #29914

pbrzosko opened this issue Mar 12, 2024 · 3 comments

Comments

@pbrzosko
Copy link

Please do not submit this issue.

  • I understand
@pbrzosko
Copy link
Author

Why this doesn't work?

test("should render define component", async ({ mount }) => {
 const component = await mount(
   defineComponent(() => {
     return () => h("div", "Rendered!");
   }),
 );
 await expect(component.getByText("Rendered!")).toBeVisible();
});

@mxschmitt
Copy link
Member

Defining them inline is not supported, see here: https://playwright.dev/docs/test-components#under-the-hood

you need to import them before and move them out to a separate file.

@pbrzosko
Copy link
Author

OK, but that's a quite functionality loss @mxschmitt. If I want a small test component, that needs to wrap tested component because it needs to provide data the tested component is injecting (provide/inject), then I need to put that in a separate file:

  1. I am polluting my source code with small wrapper components only used in tests
  2. I can not reuse this wrapper component in other tests, as it is not possible to provide a custom component as a slot [Feature] Component as slot #15900 (comment), so I need to hardcode wrapped component in it

This seems like a common use case to me. For example in React you can imagine Providers being there for tests, so that component can be tested properly.

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

No branches or pull requests

2 participants