typescript - TypeScript 和 Cypress 无法在自定义 cypress 命令中返回 true/false
问题描述
Cypress.Commands.add('checkIfTenantExist', (tenantName: string) => {
let result: boolean = false;
getTenant()
.each(($tenant) => {
if ($tenant.text() === tenantName){
result = true;
}
})
.then(() => {
return result;
});
});
我使用 cypress 和 typescript 编写测试。我想添加返回 bool 的自定义 cypress 命令。即使在 if 块中更改了它,它也总是返回 false。你能帮我解决这个问题吗?
解决方案
它工作正常,假设getTenant()
返回一个或多个元素(它应该考虑你跟随它.each()
)。
但是您使用自定义命令的方式可能不正确。
它应该与一个.then()
cy.checkIfTenantExist('something').then(exists => {
// further tests here
})
或与.should()
cy.checkIfTenantExist('something').should('eq', true)
推荐阅读
- java - 选择随机数组元素
- javascript - React Native - 如何选择图像然后发送到另一个屏幕
- java - Maven 清理问题 - 不可解析的导入 POM - 无法从 NEXUS 传输工件
- java - doThrow() 有效,但 thenThrow() 无效
- r - 使用批处理文件中的共享网络的连接字符串
- node.js - 在 heroku 上部署节点后端后出现错误 503。有谁知道为什么会这样?
- html - 根据文本文件上的内容更改以 HTML 编写的网站
- excel - 在 Excel 中查找最大值并返回具有重复项的相邻单元格值
- c# - IExtensionConfigProvider 未初始化或与 Microsoft.Azure.WebJobs v3 绑定
- typescript - 派生类中的打字稿推断函数参数