Currently, I am utilizing the buefy
css library in conjunction with the vue.js
framework.
The challenge I am facing involves unit testing my vue component (Foo
), which includes the b-table
component from buefy
:
<b-table :data="foo" class="container" style="width: 50%">
<b-table-column v-slot="props">
<b-icon
pack="fas"
icon="times"
class="is-clickable"
@click.native="doSomething(props.row)"
></b-icon>
</b-table-column>
</b-table>
Take note of the embedded b-icon
Within the Foo.spec.js
test file, my objective is to mount the component using shallowMount
from vue-test-utils
:
import Buefy from "buefy";
import { shallowMount, createLocalVue } from "@vue/test-utils";
import Foo from './Foo.vue'
const localVue = createLocalVue();
localVue.use(Buefy);
const wrapper = shallowMount(Foo, {
localVue,
});
Subsequently, I intend to utilize the returned wrapper to interact with the b-icon
component which should be nested within the table column.
const icon = wrapper.find('.is-clickable')
icon.vm.$emit('click')
However, I encounter an error:
TypeError: Cannot read property '$emit' of undefined
Upon inspection, the b-icon
seems to be absent within the wrapper as confirmed by wrapper.html()
:
<b-table-stub data="[object Object],[object Object]" columns="" headercheckable="true" checkboxposition="left" isrowselectable="[Function]" isrowcheckable="[Function]" checkedrows="" mobilecards="true" defaultsortdirection="asc" sorticon="arrow-up" sorticonsize="is-small" sortmultipledata="" currentpage="1" perpage="20" showdetailicon="true" paginationposition="bottom" rowclass="[Function]" openeddetailed="" hasdetailedvisible="[Function]" detailkey="" detailtransition="" total="0" filtersevent="" showheader="true" class="container" style="width: 50%;">
<b-table-column-stub visible="true" thattrs="[Function]" tdattrs="[Function]"></b-table-column-stub>
</b-table-stub>
The disappearance of b-icon
is perplexing.
Attempting a full mount via mount
does not provide a solution either:
<div class="b-table container" style="width: 50%;">
<!---->
<!---->
<!---->
<div class="table-wrapper has-mobile-cards">
<table class="table">
<!---->
<tbody>
<tr draggable="false" class="">
<!---->
<!---->
<!---->
</tr>
<transition-stub name="">
<!---->
</transition-stub>
<!---->
<tr draggable="false" class="">
<!---->
<!---->
<!---->
</tr>
<transition-stub name="">
<!---->
</transition-stub>
<!---->
<!---->
</tbody>
<!---->
</table>
<!---->
</div>
<!---->
</div>
What steps should be taken to access the data / components nested within the table columns?
For additional information, here are the respective links to the b-table
documentation and source code: Documentation and Source Code