javascript - 是否可以从非规范代码中将事件记录到赛普拉斯?
问题描述
假设我有一个简单的代码文件:
实用程序.js
function add(x, y){
return x + y;
}
util.spec.js
describe("utils", ()=>{
it("should add 2 and 4 together", ()=>{
sum = add(2,4);
expect(sum).to('eq', 6);
})
});
是否可以直接在add()
将事件记录到柏树输出的函数中添加一些命令?测试在远程服务器上运行,并且需要详细日志。
像这样的东西: util.js
function add(x, y){
// cy.log('add function was just called with:', {x, y})
return x + y;
}
解决方案
赛普拉斯命令只是 javascript,所以是的......当你尝试它时发生了什么?
请记住,您不能从函数返回命令值,并且时间可能不是您所期望的,但作为“副作用”应该没问题。
时序/顺序
function add(x, y){
cy.log('add function was just called with:', {x, y}) // logs 2nd
return x + y;
}
describe("utils", ()=>{
it("should add 2 and 4 together", ()=>{
sum = add(2,4);
console.log(sum) // logs first
cy.wrap(sum).should('eq', 6)
})
});
推荐阅读
- mysql - Laravel change() 方法在 mysql 8 中抛出错误
- jquery - 需要用新数据初始化时不能破坏数据表
- xml - 有条件地复制 XSLT 1.0 中的模板(优化调用模板)
- azure-ad-b2c - Azure AD B2C - 审核日志/登录日志添加其他字段
- python - 计算产品序列不起作用[python]
- node.js - 如何在 NodeJS Express 应用程序的其他地方使用连接
- powershell - 如何获取虚拟环境的名称以显示在 VS 代码终端中
- c# - 使用通用处理程序 ASHX 提供音频
- c# - 如何使用命令行或 API 访问 ADO 的共享查询?
- c# - 用户删除断言