【发布时间】:2016-05-11 19:12:49
【问题描述】:
我正在为 node.js 代码编写一些单元测试,并使用 Sinon 来存根函数调用
var myFunction = sinon.stub(nodeModule, 'myFunction');
myFunction.returns('mock answer');
nodeModule 看起来像这样
module.exports = {
myFunction: myFunction,
anotherF: anotherF
}
function myFunction() {
}
function anotherF() {
myFunction();
}
Mocking 显然适用于 nodeModule.myFunction() 之类的用例,但我想知道在使用 nodeModule.anotherF() 调用时如何在 anotherF() 中模拟 myFunction() 调用?
【问题讨论】:
标签: node.js unit-testing sinon