arrow_back Back to Notebook
typescript/sinonjs
typescript/sinonjs
February 1, 2019

Why and How you should use a Sinon Spy

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
}

Thanks for reading!

John Wiseman

Full-Stack Software Engineer building scalable digital solutions. specializing in modern web technologies and mission-critical systems.

© 2026 Wiseman Systems Pty. Ltd.

Navigation

Start a Conversation

Ready to discuss your next project? Let's build something extraordinary together.

Get in Touch