javascript - 在赛普拉斯,我的餐桌数来不及评估
问题描述
我正在传递一个 var "rows" 以分配给我的赛普拉斯表长度函数(表行数),但它是在我需要在以后的评估中使用它之后设置的(所以总是失败,因为它仍然是 0 )。毫无疑问,这是由于我对 Javascript 的了解很差,但是我怎样才能确保它在使用之前被设置好呢?
代码:
// get a count of all the current table rows
let rows = 0;
cy.get('table').find('tr').its('length')
.then((l) => {
console.log(l + ' rows detected')
rows = l
console.log(' rows set to ', rows)
// NOTE this is set to 18 but only
// after I have done the evaluation below
})
cy.get('table').find('tr').its('length')
.should('be.lt', rows)
//this is always still 0 at this point
解决方案
把它放在链中就可以了:
// get a count of all the current table rows
let rows = 0;
cy.get('table').find('tr').its('length')
.then((l) => {
console.log(l + ' rows detected')
rows = l
console.log(' rows set to ', rows)
// NOTE this is set to 18 but only
// after I have done the evaluation below
//this should now work
cy.get('table').find('tr').its('length')
.should('be.lt', rows)
})
推荐阅读
- python - 如何让 Discord.py 两次响应单个消息事件
- split - f-string 分隔新行
- swiftui - (SwiftUI) Kingfisher ForEach 问题
- excel - 如何根据最大值将单元格值拆分为多个单元格?
- c++ - 我试图实现 QuickSort 但将垃圾数组元素作为输出
- stetho - Stetho 无法在 chrome 版本 89.0.4389.72(官方版本)(x86_64)中工作
- java - 我如何完成这个 sinc 低通滤波器的编写
- javascript - 如何在 Nuxt 中使用 TinyMCE?
- javascript - javascript中的Wordpress模板目录
- python - 将矩阵形状数据框更改为表格数据框