使用 Jest / VueJS 按钮单击测试失败

Ste*_*veV 3 vue.js jestjs vue-test-utils

我正在尝试启动一个按钮单击图像,但是在运行测试时,它不断出错 find did not return cal-modal, cannot call trigger() on empty Wrapper

我究竟做错了什么?下面非常非常简化的代码:

日历.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>

Run Code Online (Sandbox Code Playgroud)

测试文件

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')
  })
Run Code Online (Sandbox Code Playgroud)

Hus*_*him 7

尝试使用ref选择器或id选择器。像这样 ..

wrapper.find({ ref: 'cal-modal' })

或者

wrapper.find('#cal-modal')