VideosMy ProjectsProgramming BlogGallery
  1. Home
  2. Blog
  3. Why and How you should use a Sinon Spy
Programming Blog

Atom/RSS Feed

typescript/sinonjs

Why and How you should use a Sinon Spy

typescript/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
}
Join my mailing list