【问题标题】:Button Click Test Failing with Jest / VueJS按钮单击测试失败并使用 Jest / VueJS
【发布时间】:2020-01-14 20:01:46
【问题描述】:

我正在尝试在图像上单击按钮,但在运行测试时,它不断出现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')
  })

【问题讨论】:

    标签: vue.js jestjs vue-test-utils


    【解决方案1】:

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

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

    或者

    wrapper.find('#cal-modal')

    【讨论】:

    • 做到了。感谢您的帮助!
    猜你喜欢
    • 2015-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-03
    • 2021-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多