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/

someone ideating on a white board with comps
Release Notes
TRYTN

July 2021 Release Notes

We’ve spent all of July trying to squash as many bugs as possible while also adding simple enhancements to make the system easier to use.

Read More »
someone ideating on a white board with comps
Release Notes
TRYTN

June 2021 Release Notes

We’ve been hard at work making the system more responsive and resilient. We’ve added another data center in the Eastern United States, updated how we

Read More »

Request a Demonstration