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

How to unit test component that uses <portal /> #260

Closed
bflemi3 opened this issue Oct 28, 2019 · 3 comments
Closed

How to unit test component that uses <portal /> #260

bflemi3 opened this issue Oct 28, 2019 · 3 comments

Comments

@bflemi3
Copy link

bflemi3 commented Oct 28, 2019

I've taken a look at your integration tests under tests/unit but each component being tested implements <portal /> and <portal-target />.

In my situation, I'm just testing a component (a modal) that only implements <portal />. The <portal-target /> is implemented in the main app component.

How do I go about testing a component created in this fashion?

@LinusBorg
Copy link
Owner

That probably depends on what you want to test.

  • Making sure that the whole thing works from start to finish including the portal in the context of your app would be best done in an e2e test, not a unit test.
  • If you want to do a unit test the interaction between your component and the content that you send through the portal. but ignore the portal functionality itself, just add the portal as an ignored element and don't install portal-vue for that test. then <portal> will be rendered as a normal element and the content of the portal stays inside of your component.

@bflemi3
Copy link
Author

bflemi3 commented Oct 29, 2019

Thank you for the prompt response Linus :). I've changed over our Modal component to implement portal-vue and the test I'm updating is testing that the content rendered in the modal is as expected (ie: I passed in a <p>Hello</p> as the child and expect that to be rendered inside the modal).

It sounds like the second bullet, ignoring the element, will accomplish what I'm trying to do. Thank you for the thorough explanation and good advice! I'll give it a try.

@LinusBorg
Copy link
Owner

I'll close this as resolved.

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