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

Allow mount method to attach to specific HTML Element rather than generically attaching to the document #1487

Closed
jnields opened this issue Mar 24, 2020 · 5 comments

Comments

@jnields
Copy link
Contributor

jnields commented Mar 24, 2020

What problem does this feature solve?

This allows the developer to attach a component within the context of a page, and potentially allows for more integrated testing, e.g. via puppeteer.

What does the proposed API look like?

Currently you offer this option in the API:

https://vue-test-utils.vuejs.org/api/options.html#attachtodocument

I believe it should be expanded to allow specification of where in the document it is attached.

const wrapper = mount(Component, {
  attachTo: document.getElementById('app'),
})

This is roughly equivalent to the API used by Enzyme
https://enzymejs.github.io/enzyme/docs/api/mount.html

@dobromir-hristov
Copy link
Contributor

Could you explain a bit what use cases will this solve?

@jnields
Copy link
Contributor Author

jnields commented Mar 24, 2020

Let's say your Vue app exists within the context of a larger page. Only one part of your app is Vue. Another part is just static HTML, another part is react.

Does it render correctly?

I can verify this by just rendering via Vue and taking screenshots with puppeteer, but then I'm not able to use all of the convenience methods of Vue test utils.

@jnields
Copy link
Contributor Author

jnields commented Mar 24, 2020

Another use case could be to test that hydration of a SSR paged works successfully. I can't use Vue test utils, as far as I know, to hydrate markup. That could be very beneficial, and, potentially, part of this API.

jnields added a commit to jnields/vue-test-utils that referenced this issue Mar 30, 2020
This allows for users to specify where in the document their component should attach, either through
a CSS selector string or a provided HTMLElement. This option is passed through directly to the
vm.$mount method that is called as part of mount.js

feat vuejs#1487
@lmiller1990
Copy link
Member

This makes sense to me. There is a PR; just need to docs to be updated @jnields and we can merge it up.

@lmiller1990
Copy link
Member

fixed in #1492

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

3 participants