javascript - 使用 sinon 存根,但未调用存根
问题描述
如何存根_http_outgoing.js
?
https://github.com/nodejs/node/blob/master/lib/_http_outgoing.js
我将var anOutgoingMessage = <OutgoingMessage>{};
其传递给我的 API 调用Get(anIncomingMessage,anOutcomingMessage)
,因为Get
有一个anOutcomingMessage.end(data)
.
在我的测试中,我想确认end
是用预期的数据调用的。
我都试过了
const outgoingMessageSpy = sinon.stub(OutgoingMessage.prototype,"end");
和
const outgoingMessageSpy = sinon.stub(anOutgoingMessage,"end");
然后我
expect(outgoingMessageSpy.called).to.be.true()
对于 1)outgoingMessageSpy.called
是错误的。2)我得到Cannot stub non-existent property end
end
OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
根据上面的链接在 _http_outgoing.js 中定义。
用我期望的参数调用此消息并确认 end 的正确方法是什么?
谢谢!
解决方案
var anOutgoingMessage = <OutgoingMessage>{};
是问题!它必须是var anOutgoingMessage = new OutgoingMessage();
。当然没有end
其他的{}
。让我发疯
推荐阅读
- ajax - 使用 ajax 和 django 进行第二次点击后,Div 显示/隐藏
- c# - 获取两个标签之间所有元素的列表
- r - 使用 dplyr 但至少保持组存在
- ruby - 主机名与服务器证书不匹配 - 使用旧的过期证书
- python-3.x - 如何在少于 30 天的日期时间中将年、月打印为 0?还是1年?
- youtube-iframe-api - Youtube url 参数 ?playlist=[video_id's] 不再工作
- batch-file - 批处理文件验证输入格式(仅限长度和数字)
- javascript - 将时区更改为另一个时区
- android - 从字符串生成 ES256 PrivateKey
- asp.net-mvc - 每次浏览器关闭时如何不让用户重新登录?