Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Textarea set to blank doesn't execute bound watcher #1732
Comments
Seems to be expected as the Try calling |
Hi @LinusBorg Thank you for your quick reply. I had already tried you proposal and it doesn't work. Same result. The watched property is not executed. |
I think this is just jest succing at simulating the change event. |
I didn't clarify it in my previous post. |
We actually cover this case explicitly by checking for |
Did you forget to declare Anyway, this is working fine for me (including Component: <template>
<div>
<textarea id="labeling-text" v-model.lazy="myProperty"></textarea>
</div>
</template>
<script>
export default {
data() {
return {
myProperty: 'ok'
}
},
watch: {
myProperty() {
this.$emit('myEvent', this.myProperty)
}
}
}
</script> Test: import { mount } from '@vue/test-utils'
import HelloWorld from '@/components/HelloWorld.vue'
it('Raises an event when textarea changes', async () => {
const wrapper = mount(HelloWorld)
const $ta = wrapper.find('#labeling-text')
await $ta.setValue('OK!!!')
console.log(wrapper.emitted('myEvent')) // => [ [ 'OK!!!' ] ]
}) |
I just forgot to include the property in the repro. Sorry! |
I just created a new project using the Vue CLI and chose 2.x when I was trying to reproduce this issue. Should be using the latest version of 2.x. If you are using Vue 3, you will need v2 of this library (which you can get with Are you still having this problem? The code above was working for me. Maybe you can post a repository with the bug so I can reproduce it? |
In a test, I'm trying to set the value of a
textarea
to blank.The textarea is bound to the model using
v-model.lazy
. with adata()
property which is linked to a watcher.If I change the textarea value using
setValue()
the watcher is executed and the test works fine.However, if I do
setValue('')
the watcher is never executed.Code:
Expected behavior:
The watcher raised the event.
Current behavior
The watcher is not executed so the event is not raied.