Adding mocha unit tests

Update: This post is now available at a new location:
https://blog.ngeor.com/2017/12/29/adding-mocha-unit-tests.html

In this post, I’ll add unit tests to the example application that I’ve been fiddling around with in the recent posts.

Continue reading Adding mocha unit tests

Advertisements

Using sinon mocks

Update: This post is now available at a new location:
https://blog.ngeor.com/2016/06/04/using-sinon-mocks.html

In the previous posts we had a look at sinon spies and stubs. There is one more technique we can use in order to orchestrate our test dependencies: mocks.

Continue reading Using sinon mocks

Using sinon stubs

Update: This post is now available at a new location:
https://blog.ngeor.com/2016/05/28/using-sinon-stubs.html

In the previous post we had a look at sinon spies. With spies, we are able to determine if a specific function was called or not. Usually the dependencies between units are more interesting, they involve units co-operating, exchanging data and so on. Spies do not suffice. Let’s have a look at another technique, using stubs. Continue reading Using sinon stubs

Using sinon spies

Update: This post is now available at a new location:
https://blog.ngeor.com/2016/05/21/using-sinon-spies.html

In the previous post, we implemented a new feature for our calculator: it makes a bell sound when you divide by zero. The bell is a simple function that the calculator calls and it is provided as a constructor dependency. We wrote a unit test for this as well, but the code for that is a bit verbose. Let’s see how we can use a mocking library like sinon to reduce and standardize the testing code. Continue reading Using sinon spies