我需要模拟'mkdirp-promise'节点模块,它公开了一个构造函数,如下所示
mkdirpPromise(dirPath)
.then(() => {
console.log('ABCDEFGH');
resolve(dirPath);
})
.catch((error) => {
console.log('HeABCDEFGHre');
const details = error.message;
const err = customError.failed_create_downloads_directory()
.withDetails(details);
reject(err);
});
我能够第一次使用 proxiquire 模拟它,如下所示:-
let mkdirpPromiseMock = sinon.stub().rejects();
const sthreeDownloadMock =
proxyquire('./../../modules/sThreeDownload', {
joi: joiMock,
fs: fsMock,
'@monotype/core-error': {
errors: {
ApiError: customErrorMock,
},
},
'aws-sdk': awsSDK,
'mkdirp-promise': mkdirpPromiseMock,
path: pathMock,
});
现在我想在第二个测试用例中覆盖 mkdirpPromiseMock
mkdirpPromiseMock = sinon.stub().resolves();
我不能。任何帮助表示赞赏。