javascript - 如何在柏树中更新别名
问题描述
我不确定我是否在柏树中正确使用它。我想要做的是更新我的别名@priceValue
,以便以后可以使用更新的别名。
这就是我在逻辑上的意思:
1:获取文本并给它一个别名priceValue
2:检查价格值以确保它包含一个字符串,然后(这是问题)-> 通过转换将别名更新为分数。字符串到分数
如何更新别名,使其现在是转换后的分数?
priceElements.priceButton().first().invoke("text").as("priceValue");
cy.get("@priceValue").then((priceValue) => {
expect(priceValue).contains("/");
math.fraction(priceValue);
})
解决方案
您也可以只更改它,无需新别名
priceElements.priceButton().first().invoke("text")
.should('contain', '/')
.as("priceValue")
cy.get("@priceValue")
.then(priceValue => math.fraction(priceValue)) // modify
.as("priceValue") // re-save
cy.get("@priceValue")
.invoke('toString')
.should('not.contain', '/') // different value
推荐阅读
- typescript - 数组解构错误地推断出创建数组的类型
- php - html2pdf 输出在 pdf 中显示希腊字符的问号
- javascript - 下载并将 c# excel 字节数组转换为 javascript blob
- javascript - 为什么容器边框会弄乱 Masonry.js 项目的放置?
- python - Pandas Dataframe 列值的类型虽然是字符串列表,但仍以字符串形式返回
- arrays - PostgreSQL:错误:数组下标超出范围
- javascript - 从对象中删除数据
- php - 数据透视表上的 Laravel Accessors & Mutators
- vue.js - 构建时服务器上的 Vue.js node_modules 文件夹不同
- javascript - Jquery:删除事件处理程序(例如'cklick'),但保留其他事件处理程序(用于'click')