I want to write a test for a VueJS watcher method, in order to verify if it's being called. The watcher method in my component is structured like this:
watch: {
value: (newValue, oldValue) => {
if (newValue.Status === 'Completed') {
...do something
}
}
}
The watcher method triggers successfully when the value changes, however, it doesn't seem to be triggered during the test.
This is how my test code looks like:
var propsData = {
"value" : {
"Status" : "Something"
}
}
it('should call the method', done => {
const Constructor = Vue.extend(App);
const spy = sinon.spy(App, 'value');
const vm = new Constructor({ propsData: propsData }).$mount();
vm.value.Status = 'Completed';
Vue.nextTick(() => {
expect(spy.called).to.be.true;
done()
})
})
I have come across some examples that could be helpful, but they haven't quite solved my issue: