vue-test-utils: wrapper.html does not display v-bind elements
Version
1.0.0-beta.20
Reproduction link
https://codesandbox.io/s/x3p3725mm4
Steps to reproduce
Could you see Todo.spec.js file, and run the test.
In the console, checked is not displayed in wrapper.html() .
What is expected?
<div>
<input type="checkbox" checked>
<span>Hello from data</span>
</div>
What is actually happening?
<div>
<input type="checkbox">
<span>Hello from data</span>
</div>
I want to show checked in the html.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 15 (9 by maintainers)
For the record, the reasoning behind removing
hasStylewas because it produce a boolean assertion (true/false) and could be achieved by accessing the style property directly:wrapper.element.style.colorAgreed @38elements . We won’t be implementing this feature because it would require changing the behavior of
innerHTML.I think Vue removes
v-bindandv-modelinputs from the markup, and manages them internally (for reactivity), so that’s why they are not shown in thewrapper.html(), which is really justwrapper.vm.$el.innerHTML.I am not sure how hard it would be to implement, maybe impossible. You would have to check any elements in
data, for example, then insert the correct value into the markup. This sounds like a pretty big change it howvue-test-utilsworks, but if it were possible to show allv-modelorvaluebindings in the markup, that would make for awesome snapshot tests.I wonder how react/enzyme handles this.
Ideally I would want to see this (not just
checked, butchecked="true")another thing that would be great to see is something like this
Hm, just tried this out @ATselikovSnp . Regular styles show up, but
v-bindones do not.We used to have a
stylemethod, but it got removed. I think the reasoning was these kind of tests are generally not good practice. At this point, because of how JSDOM and Vue’s binding works, I don’t think you can test what you want.On alternative is to move the logic into a
computedproperty. This, for example, works:Test
Console.log output:
I can do
element.style.colorand getgreen.When the checkbox is checked in browser, , there is not always the
checkedattribute oninputelement. This is not bug. I think it is incorrect to change the behavior ofwrapper.html().