Testing my Vuejs component is a top priority for me. To make sure everything runs smoothly, I rely on avoriaz, jsdom, mocha, and chai.
<template>
<div id="test-event" class="test-event">
<button id="button" v-on:click="plusClick" v-bind:value="click_count">{{click_count + " elements"}}
</button>
</div>
</template>
<script>
export default {
data () {
click_count: 0
},
methods: {
plusClick(event) {
console.log("element = ", this.click_count)
return this.click_count = Number(event.target.value) + Number(1);
},
get_click_count() {
console.log(" => ", this.click_count);
return this.click_count;
},
watch : {
click_count: function(element) {
console.log("element = ", element);
}
}
</script>
In my unit test:
it('should render the button when called ', function() {
const wrapper = mount(Bar);
expect(wrapper.contains('#test-event')).to.equal(true);
var test_event = wrapper.find('#test-event');
expect(test_event[0].contains('button')).to.equal(true);
var button_test = test_event[0].find('button')[0];
button_test.simulate('click');
button_test.simulate('click');
console.log( wrapper.data().click_count );
// The value remains at 0
console.log( wrapper.methods.get_click_count() ):
// Error - wrapper.methods.get_click_count() is not a function
console.log( wrapper.methods.get_click_count ):
// Undefined
button_test.simulate('click');
button_test.simulate('click');
});
Despite my efforts, I'm struggling to retrieve the updated value of click_count. Any suggestions on how to capture this value?