Testing 使用testcafe监视窗口函数

Testing 使用testcafe监视窗口函数,testing,automation,automated-tests,e2e-testing,testcafe,Testing,Automation,Automated Tests,E2e Testing,Testcafe,我想用testcafe测试窗口对象上的函数是否使用某些参数执行。可以用Testcafe吗 函数调用如下所示: window.myObject.myFunction({customObject: true}); 可以使用API在窗口对象中创建间谍函数。请查看以下测试示例: 从“testcafe”导入{ClientFunction}; 夹具`新夹具` .第页`https://cf51n.csb.app/`; const spyOn=ClientFunction(()=>{ //创建一个数组,在其中

我想用testcafe测试窗口对象上的函数是否使用某些参数执行。可以用Testcafe吗

函数调用如下所示:

window.myObject.myFunction({customObject: true});
可以使用API在窗口对象中创建间谍函数。请查看以下测试示例:

从“testcafe”导入{ClientFunction};
夹具`新夹具`
.第页`https://cf51n.csb.app/`;
const spyOn=ClientFunction(()=>{
//创建一个数组,在其中存储有关“myFunction”调用的信息
window.myFunctionSpyData=[];
//存储原始的“myFunction”值
window.orirginalFunction=window.myObject.myFunction;
window.myObject.myFunction=函数(){
//保存有关当前通话的数据
window.myFunctionSpyData.push(…参数);
//调用原始的'myFunction'值
orirginalFunction(…参数);
}
});
const getSpyData=ClientFunction(()=>{
//从客户端检索有关myFunction调用的数据
返回window.myFunctionSpyData;
});
const spyOff=ClientFunction(()=>{
//恢复原始myFunction值
window.myObject.myFunction=window.orirginalFunction;
删除window.spyData;
});
测试('新测试',异步t=>{
等待间谍();
等待t.点击('btn');
常量数据=等待getSpyData();
等待间谍();
等待
.expect(data.length).eql(2)
.expect(数据[0]).eql('1')
.expect(数据[1]).eql('2');
});