Description
I want to be able to test my Single File Vue Component by selecting an option in a Vue Child component. I need to trigger the Vue watcher that watches selectedFooItem
. I am using mocha-webpack
and js-global
according to the vue-test-utils
docs.
This is related to this issue: #128 , and my SO ticket. I also tried going the chat route but Discord tells me I don't have permission to send messages in that channel in vue-land.js.org.
I'm testing a Vue 2 component that has an el-select
child component from ElementIO . The main difference in my example is that there is a child Vue component as opposed to HTML elements (i.e. can't rely on .find("select")
. It looks like this:
// Foo.vue
<template lang="pug">
.foo-item(:class="className")
el-select(v-model="selectedFooItem",
value-key="name",
@click="onClick",
@visible-change="onVisibleChange")
el-option(v-for="entity in unselectedFooItems",
:label="foo.name",
:value="foo",
:key="foo.name")
</template>
<script src="./Foo.js"></script>
What doesn't work:
1.
const selectBox = wrapper.find("el-select");
selectBox.trigger("click");
wrapper.find('el-option').trigger("click")
I see onClick
being called twice (one from el-option
). I think this refers to the event propagation behavior the issue I referenced was talking about. But, my watcher does not detect changes.
wrapper.find('el-option').trigger("change")
Still, watcher does not detect changes.
const selectBox = wrapper.find("el-select");
selectBox.trigger("change", { /* the value */ })
My work around
Right now I'm resorting to
wrapper.setData({ foo: 'bar' })
or
wrapper.vm.selectedFooItem = "bar"