node.js - sinonStub.called 打印错误,尽管我正在调用该函数
问题描述
我正在使用 sinon 在节点 js 应用程序上运行测试。我希望 sinonStub.call 为真,但这打印为假。我间接调用函数(函数内的函数调用)。我在下面给出了代码片段
规范.js
describe.only('creating stub for Accounts method',function(){
mockResponse=
[
{
"AccountID": "xyz",
....
}
]
req1= {
user:{
id:""
},
},
res1= {
json:sinon.spy()//Is this correct
}
it('should call getActivatedAccounts and always this mock response',function(){
var getAccountsStub=sinon.stub(devices,'getAccounts').returns(mockResponse);
devices.getActivatedResponse(req1,res1);
console.log(getAccountsStub.called);//I expect this to be called
})
实际.js
function getActivatedResponse(req, res) {
if (!req.user || !req.user.id) {
let reply = {
status : "SUCCESS",
data : []
}
res.json(reply);
//console.log(reply);
} else {
getActivatedAccounts(req.user.id).then(
function(reply) {
res.json(reply);
},
function(error) {
console.log(error);
}
);
}
function getAccounts(Id){
....
....
returns promise;
}
解决方案
推荐阅读
- kubernetes - 从另一个 pod 连接到 svc 时连接被拒绝
- php - 在 html 文件中多次调用带有按钮的 php 文件
- java - 如何将并行数组从高到低排序
- python - Python将不同的变量分配给类对象
- phpunit - phpunit coverage-unit 不生成报告
- python - 如何告诉 Jenkins 运行 Python Flask 应用程序,然后进行 Selenium 测试,然后关闭 Flask 应用程序?
- java - 以下 SQL 语句最多使用 11 GB RAM,如何优化 RAM 使用?
- python - 如何将多个列表列表转换为列表?
- ios - CocoaPods 找不到 pod "React/Core" 的兼容版本
- python - 读取和扭曲图像(-215:断言失败)size.width>0 && size.height>0 in function 'cv::imshow'