O'Reilly logo

TypeScript Microservices by Parth Ghiya

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Sinon

Quite often, microservices need to call other microservices, but we don't want to call the actual microservice; we just want to focus on whether the method was called

or not. For this, we have Sinon, a framework that gives us the options of mocks and spies, which fulfill our purpose by providing mock responses or creating a spy service. It provides the following:

  • Stub: A stub is a dummy object with a prerecorded and specific response.
  • Spy: A spy is a kind of hybrid between the real object and the mock. Some methods are shadowed by the spy object.
  • Mock: A mock is a dummy object replacing the actual object.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required