javascript - 如何用 cypressjs 测试 quasar 组件?
问题描述
我使用 quasar 来构建我的 webapp,并且我对使用 CypressJS 测试组件有疑问。
我在我的 webapp 上使用https://quasar.dev/vue-components/select#Example--Generating-multiple-values,它看起来如下:
和组件代码:
<q-select
filled
label="Enter your interests"
new-value-mode="add-unique"
v-model="user_interests"
use-chips
multiple
option-value="id"
option-label="description"
input-debounce="0"
:options="interests_filtered"
@remove="interestRemoved"
@filter="filterInterests"
style="width: 400px"
/>
q-select
例如,如果组件q-select
包含任何值,我想编写一个测试。
我的问题是,如何用 CypressJS 编写这样的测试?
解决方案
首先给你的q-select
组件一个 id 属性:
<q-select id="select"></q-select>
获取具有 id 的组件,单击它并检查包含所需选项的 span 元素,然后单击它。
cy.get("select").click()
cy.get("span").contains("LABEL_OF_OPTION").click()
不是很完美,但值得的方法。
推荐阅读
- excel - 创建自定义日期格式时遇到问题
- flowtype - 作为类实例的函数参数的流类型
- opengl - 将立方体贴图投影到 2D 纹理
- android - 通过 AppCenter 部署时应用屏幕为空白
- c - 为什么 * 和 % 在这条规则中表现不同?
- python - 我如何在python中验证以下输入(十六进制间隔值)
- ssl - 但是,托管具有活动 SSL 证书的网站,导航到 www.example.com 会导致我访问 Http 而不是 Https
- javascript - 需要帮助使用某种类型的样式与反应
- android - Firebase 文档未删除
- c++ - 将二维数组中的符号分成 2 组