vue.js - 等待按钮单击以查找元素 - VueJS/Jest
问题描述
我正在编写一个测试以查看单击按钮后是否弹出模式窗口,并且不确定如何告诉测试等待单击的正确方法。
因此,例如,假设我有一个模式窗口,在单击图像时显示如下:
日历.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>
<b-modal id="date-time-modal" ref="date-time-modal" hide-footer title="Modal Title">
<div class="d-block text-center">
<p>This is a modal window</p>
</div>
</b-modal>
</template>
日历.SPEC.JS
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')
})
在寻找“点击”事件发生之前,最好的方法是什么?
解决方案
推荐阅读
- javascript - 使用 google firebase 开发混合移动应用程序
- python - 无法使用 CreateView 保存表单(Django、Python)
- node.js - 有没有更简单的方法可以从第 4 分钟到第 9 分钟等每 5 分钟编写一次 cron 作业
- html - 如何将此文本与图像对齐?(在堆栈溢出上浏览太久,解决方案似乎不起作用)
- ssl - 使用 HA 代理进行反向代理
- sql - 从两个表计算分区并在bigquery中使用小于或等于索引的索引
- rest - 在 golang GRPC 服务器中处理 REST 请求
- c# - 在没有 ref (C#) 的方法中更改属性参数时会发生什么
- android - Moshi:为什么不需要注册生成的 JsonAdapters?
- python - 如何实现多处理以便将输出保存到数据库?