Javascript 使用sinon存根,但未调用存根
如何存根Javascript 使用sinon存根,但未调用存根,javascript,node.js,unit-testing,mocha.js,sinon,Javascript,Node.js,Unit Testing,Mocha.js,Sinon,如何存根\u http\u outgoing.js? 我有var anOutgoingMessage={}我将其传递到我的API调用Get(一条传入消息,一条传出消息)中Get有一条anOutcomingMessage.end(data) 在我的测试中,我想确认end是用预期数据调用的 我两个都试过了 const outgoingMessageSpy=sinon.stub(OutgoingMessage.prototype,“end”) 及 const outgoingMessageSpy=s
\u http\u outgoing.js
?
我有var anOutgoingMessage={}代码>我将其传递到我的API调用Get(一条传入消息,一条传出消息)
中Get
有一条anOutcomingMessage.end(data)
在我的测试中,我想确认end
是用预期数据调用的
我两个都试过了
const outgoingMessageSpy=sinon.stub(OutgoingMessage.prototype,“end”)代码>
及
const outgoingMessageSpy=sinon.stub(一个outgoingmessage,“end”)代码>
然后我
expect(outgoingMessageSpy.called).to.be.true()
对于1)outgoingMessageSpy.called
就是false。对于2)我获取无法存根不存在的属性结束
end
在_http_outgoing.js中定义为OutgoingMessage.prototype.end=函数结束(块、编码、回调){
,如上面的链接所示
什么是存根此消息并确认使用我期望的参数调用end的正确方法
谢谢!var anOutgoingMessage={};
就是问题所在!
它必须是var anOutgoingMessage=newoutgoingmessage();
。当然在{}
中没有end
。
把我逼疯了