【发布时间】:2021-07-26 09:14:37
【问题描述】:
如何存根_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 在 _http_outgoing.js 中定义为 OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {,根据上面的链接。
使用我期望的参数调用此消息并确认 end 调用的正确方法是什么?
谢谢!
【问题讨论】:
标签: javascript node.js unit-testing mocha.js sinon