Package Spotlight: Sinon

Package Spotlight: Sinon

Testing is only as good as the test writers ability to spying, stubbing, and mocking the code they are testing.

For reference for those who don’t work with unit and integration tests I’d like to quickly go over some definitions.

Spies are a way to interject a spy into code that is being tested so you can literally spy on the code. You use these spies to look into the code as it’s working.

Stubs, on the other hand, are a stub of the code that’s being executed but not being tested. An example is you call a function that perhaps executes some code in another module. You don’t want to execute that code but perhaps you want to confirm the code is executed as expected. You can create a stub to simply assert that the code was triggered as expected. Another good use for stubs is to return specific cases to test all aspects of the code.

Lastly there are mocks which are fake items that code relies upon. A common use case for a mock is a server. Perhaps you make a third-party call to an external provider. You mock that call so you don’t actually make that external call in your tests.

Sinon is clean, small, and powerful. It’s a tool that any test writer cannot be without. We use Sinon heavily as part of our JavaScript testing strategy.

Package Name: Sinon.JS
Website: https://sinonjs.org/

a woman sitting at a table using a laptop computer
Blog
Virginia

Seven Ideas for Slow Season

It’s hard to avoid having an “off-season” in any business. This is especially true in the tourism industry. By its very nature, the travel industry

Read More »

Request a Demonstration