-
Notifications
You must be signed in to change notification settings - Fork 262
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
Emitting v-model event leads to unexpectedly updated prop value #440
Comments
Good point... there (is?) was a discussion around this where people want the opposite to happen. I think it probably led to the PR you linked. Regarding "... With this change, components under test do not behave in the same way as in normal operation ..." is this true? In most situations emitting the update event will automatically update the v-model bound value, won't it? No need to do any catching/handling. Either way, it seems like some users would like |
If you are using the I always prefer being explicit, especially when it comes to tests, so I like my suggestion (of course :)). But I realize not everyone is me and that it might seem like unnecessary boilerplate code. From the discussion you linked I also like the |
const wrapper = mount(Foo, {
props: {
one: 'hello',
two: 'world',
},
vModel: ['one'],
}) Internally test-utils would add |
@nekosaur So if I understand right your component is like I think having a While this discussion is resolved you could still do the |
My specific use case is probably not a very common one, it only served to highlight the actual issue for me. These two markups have very different behaviors in Vue, right. The first one will only ever pass down a value from outside the component, while the second one will update the outside value with a new one from inside the component. <component :value="value" /> <component :value="value" @update:value="value = $event" /> The current test-utils behavior does not match this. Mounting the first example and emitting an This is what I would consider to be the corresponding test-utils mounts. mount(Component, {
props: {
value
}
}) mount(Component, {
props: {
value,
onUpdateValue
}
}) In Vue you have to explicitly opt in to 2-way prop bindings with either |
Right, I think you're right. But given vue gives the syntactic sugar of Apart from that I agree however, I think |
I am not sure adding more config to reduce boilerplate by a few lines is really a good trade-off. Anyone can read boilerplate, but more configuration options leads to more complexity. This doesn't mean it's a bad idea; I am just not 100% sold on more features when you might be able to accomplish the same thing with a few lines (or a util function). I think we probably need to revert to the original behavior, since that is how v1 works, and we want to have as few breaking changes as possible. As for |
I have a scenario where I want to test that interacting with a component (that results in emitting a v-model event) does not lead to a state change in the internals of a component.
Here is a simplified version of what I'm trying to do
Currently this fails on the second expect with a received value of
baz
. This to me feels very strange and unintuitive. The component has emitted an event, but I have done nothing to catch it and subsequently update state to trigger a re-render, as I need to do in a real Vue app. Yet the props have been modified.The change was introduced in this PR #393. With this change, components under test do not behave in the same way as in normal operation.
edit:
Something a bit closer to real usage would be if you could perhaps do something like this, if you need the 2-way binding to be automatic.
Replacing the code from the PR with the following works, but I've no idea how stable it is.
The text was updated successfully, but these errors were encountered: