jestjs - Jest:编写所有需要首先断言某些步骤的测试的正确方法是什么?
问题描述
我已经开始开玩笑地编写一些 UI 测试,现在,我遇到了需要测试模态的情况。模态仅在单击按钮后打开。我的代码如下。我想知道我是否可以将getButton
and getModal
with 断言提取到另一个函数中,以便在每次测试之前运行。我想把它放在 beforeEach 中,但我不确定这是否是最佳做法。任何建议都是最受欢迎的。
it('should open Modal when click on button', async () => {
const button = getButton();
expect(button.isDisplayed()).to.be.true;
const modal = getModal();
expect(modal.isDisplayed()).to.be.true;
});
it('should contain text and close icon', async () => {
const button = getButton();
expect(button.isDisplayed()).to.be.true;
const modal = getModal();
expect(modal.isDisplayed()).to.be.true;
/* * some other code....*/
});
解决方案
推荐阅读
- python - 导出所有帧
- r - 将训练数据中的robustscale应用于R中的任何数据集
- discord - Discord.js - .then 即使在函数中也没有定义?
- r - 如何以高分辨率保存绘图,然后在 RMarkdown 针织文件中显示
- javascript - 如何验证另一种语言的元数据长度?反应原生
- reactjs - Apollo 客户端 - 具有来自对象的计算值的本地字段
- javascript - 如何使用 CSV 数据并在 p5.js 中绘图
- javascript - NextJS 作为后端 JS
- azure - 如果在 Key Vault 中更新了机密,是否应该重新启动 Azure Functions 应用?
- containers - 如何仅指定图像名称在 cri-o 中启动容器?