我正在尝试在图像上启动按钮单击,但是在运行测试时,它会不断显示find did not return cal-modal, cannot call trigger() on empty Wrapper
错误
我在做什么错?下面的代码非常简化:
CALENDAR.VUE
<template>
<div class="col-xs-6 text-right">
<b-img ref='cal-modal' id='cal-modal' class="cal-icon" @click="displayCal" v-b-modal.date-time-modal src="/static/img/ico.png"></b-img>
</div>
</template>
测试文件
import {createLocalVue, mount} from "@vue/test-utils";
import Calendar from '@/components/Calendar.vue'
import BootstrapVue from "bootstrap-vue";
const localVue = createLocalVue()
localVue.use(BootstrapVue)
it('display cal', () => {
const wrapper = mount(Calendar, {localVue});
wrapper
.find('cal-modal')
.trigger('click')
})
答案 0 :(得分:1)
尝试使用ref
选择器或id
选择器。像这样..
wrapper.find({ ref: 'cal-modal' })
或
wrapper.find('#cal-modal')