我有这样的想法:
sandbox.stub(rp, 'get').resolves(successResponse)
它在遇到以下代码时返回我的自定义响应:
return await rp.get(url, options)
但我怎么能这样做:
sandbox.stub(rp).resolves(successResponse)
哪个可以在点击此代码时返回自定义响应?
return await rp(url, options)
当我尝试“存根”整个对象时,在运行测试时会出现以下错误:
TypeError: Attempted to wrap undefined property undefined as function
at wrapMethod (node_modules\sinon\lib\sinon\util\core\wrap-method.js:70:21)
at stub (node_modules\sinon\lib\sinon\stub.js:58:44)
at Object.stub (node_modules\sinon\lib\sinon\collection.js:93:33)
rp
是
request-promise-native
,其中包装
request