-
Notifications
You must be signed in to change notification settings - Fork 264
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
Inconsistent .text()
behaviour on components using v-if
#342
Comments
Apologies if this issue should have been submitted against https://github.com/vuejs/vue-test-utils-next 🤦 |
No worries, just transferred the issue to the right repo :) |
Hmmm interesting one. I don't have a solution off the top of my head, I guess we just write some code (regexp?) to remove the comments when using That should be quite easy. Would you like to make a PR? If someone has a better solution, by all means share! |
I'm not sure if a regexp would solve this as comment content is not returned by e.g.
Mounting this component, The issue only occurs on components with single root nodes using |
I understand this is surprising, but this works as expected right? If you have a comment node, We could also consider returning an empty string for comment nodes as I suspect nobody really needs to get the content of a comment (it is a breaking change though). |
I opened #351 if we want to go ahead and return an empty string for comments |
Inconsistent
.text()
behaviour on components usingv-if
❌ When mounting a component that has a single root node with a
v-if
, when thev-if
is falseywrapper.text()
returns the text of the HTML comment<!--v-if-->
inserted in the DOM. SeeRootIf.vue
below.✅ When mounting a component that has a single node with a
v-if
wrapped with a<div>
, when thev-if
is falseywrapper.text()
returns and empty string. SeeWrappedIf.vue
below.✅ When mounting a component that has two root nodes, first with
v-if
and second withv-else
,wrapper.text()
returns only the text of the visible node. SeeRootIfElse.vue
below.Steps to reproduce
RootIf.vue
RootIfElse.vue
WrappedIf.vue
__tests__/wat.spec.js
Expected behaviour
When mounting a component that has a single root node with a
v-if
, when thev-if
is falseywrapper.text()
should return an empty string.Actual behaviour
wrapper.text()
returns"v-if"
Possible Solution
Possible workaround is to add unnecessary additional empty root nodes with
v-else
to get expected behaviour while running tests.The text was updated successfully, but these errors were encountered: