0

i am not able get the resolved value in the response the promise stub returns undefined

   otpHelper.sendOtp = (number) => {
       console.log('number', number);
  return Promise.resolve({ status: '0', requestId: 'hdgfhsgdfdsgfjsgdfj' });
};

sendOtpStub = sinon.stub(otpHelper, 'sendOtp');
const otpHelperStub = proxyquire('../routes/register', {
  '../utils/otpHelper': {
    sendOtp: sendOtpStub,
    // checkOtp: checkOtpStub,
  },
});

sendOtpStub is called but the value that i get is undefined i need to get the resolved value from the promise.its resolving to undefined am using if am not using the stub its working as expected. if i put sendOtp: otpHelper.sendOtp its working as expected but when i make it as a stub its not returning the resolved value.

4

1 回答 1

0

存根不调用原始方法,这就是它应该工作的方式。你想要的是一个间谍,它包装了原始方法并在调用时调用它。

sinon.spy(otpHelper, 'sendOtp')
于 2018-10-21T17:02:14.043 回答