【发布时间】:2020-07-31 01:35:50
【问题描述】:
有一个文件helperFunction.js,长这样:
module.exports = (arg1, arg2) => {
\\function body
}
现在,在 file.js 中,可以通过以下方式简单地调用此函数:
let helperFunction = require('./helperFunction.js');
//some code here
let a=1, b=2;
let val = helperFunction(a,b);
//some code here
为了测试 file.js,我想存根 helperFunction。但是, sinon.stub 的语法如下:
let functionStub = sinon.stub(file, "functionName");
在我的例子中,文件名本身就是函数名。我现在如何为 helperFunction 创建存根?或者还有什么我可以做的吗?
【问题讨论】:
标签: javascript node.js unit-testing sinon stub