Why and How you should use a Sinon Spytypescript/sinonjs

Sinon spys and stubs are very using in testing code. Spys and Stubs allow you to verify if a function was called and how it was called (args).

Thus allowing you to easily test your code.

Import sinon

import * as sinon from 'sinon';

Declare the Spy

const spy: sinon.SinonSpy = sinon.spy();

Test the spy

You can now test against the spy.

if(spy.called) {
    // spy has been called