Sinon.js best practices for spies, stubs and mocks

Tags:

Sinon is one of the most important tools for testing, as without it writing tests for more complex pieces of code such as Ajax, networking, databases, etc. would become difficult. In this article, I’ll show you the best practices for using Sinon, so you’ll be able to apply it to your own projects more easily. What are the differences between …

Unit testing Ajax requests with Mocha

Tags:

Ajax requests can easily go wrong. You can’t guarantee the connection and the server always work correctly. They are also often used to send user input to the server and back, so it’s vital the data is handled correctly. But testing them can be tricky. It’s asynchronous, and also a good unit test must be isolated, so how can we …

How to unit test NodeJS HTTP requests?

Tags:

I have a nodejs app where I wanted to unit test some HTTP requests. Node usually makes things simple, so I expected this to be like that too… but I soon discovered that this was not the case at all. When unit testing, you don’t want HTTP requests to go out and affect the result. Instead you create a fake …