how to to make sinon return non promise I do mock expect Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of how to to make sinon return non promise I do mock expect without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I am using sinon to mock a return for a function and here is my code:

  sandbox.mock(monitoring).expects('getHttpRequestDuration').resolves({
    startTimer: () => {}
  });

The problem here is the return is wrapped in a promise and the actual function is not using any await

 const end = httpRequestTimer.startTimer(); 

is there a way I can return only

     {
        startTimer: () => {}
      }

not wrapped in a promise?

Answer

resolves returns a promise. The equivalent method in sinon to return a value is .returns:

  sandbox.mock(monitoring).expects('getHttpRequestDuration').returns({
    startTimer: () => {}
  });

See stub.returns in our docs.

We are here to answer your question about how to to make sinon return non promise I do mock expect - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji