Unit Testing with Sinon.js
Stubs and Spies
A sinon spy allows the code to be called without breaking the rest of the application, and it can be tested to check whether it was called or not and how many times it was used.
A stub is essentially same as a spy except that it has a predetermined behaviour such as what to return when an ajax call is stubbed.
“Fake timers is a synchronous implementation of setTimeout and friends that Sinon.JS can overwrite the global functions with to allow you to more easily test code using them.”
This is particularly useful when you are trying to test time specific code. For example when a given dataset is dependent on system time and don’t want to keep changing the test time.
For further information on any of these functions, there are detailed documentation on http://sinonjs.org
Junior Software Developer
Originally published at techbrunch.gousto.co.uk on January 18, 2017.