【发布时间】:2019-07-15 18:49:18
【问题描述】:
我有一些文件mainFile 使用方法helperMethod,这是一个在文件helperFile 中返回Promise 的方法。如何存根从helperMethod 返回的内容?
这是我目前所拥有的 -
帮助文件:
export function helperMethod() {return a Promise}
module.exports.helperMethod = helperMethod;
主文件:
import helperMethod from helperFile;
methodInMainFile() {console.log(helperMethod);}
主文件测试:
import methodInMainFile from mainFile;
import * as utils from helperFile;
sinon
.stub(utils, 'helperMethod')
.returns(Promise.resolve(madeUpResponse));
methodInMainFile();
上面的代码打印Promise { undefined }。如何让它打印Promise { madeUpResponse }?我不认为 helperMethod 实际上被调用(因为它不应该被调用),因为我在那里记录了一些东西并且它从未显示。
【问题讨论】:
标签: javascript typescript sinon