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 …

What’s the difference between Unit Testing, TDD and BDD?

Tags:

When you’re just getting started with automating your JavaScript testing, there’s a lot of questions. You’ll probably see people talk about unit testing, TDD or Test-Driven Development, and BDD or Behavior-Driven Development. But which one of them is the best approach? Can you use all of them? I’ve talked to a number of JavaScript developers, and there seems to be …

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 …

How to automatically run unit tests from a git push

Tags:

Typically when working on code that has tests, you would want to make sure your tests pass when you share your code with other people. It’s generally a good idea to run the tests once in a while too, but why do it manually when you can automate? In this post I’ll show a simple shell script you can use …

Unit-testing essentials

Tags:

Here’s some essential unit-testing posts I’ve written recently. While some of them have examples in PHP, they should still be useful in other languages as well. Unit testing PHP series Unit testing introduction Writing and running tests Writing tests for exsisting code Mock Objects and testing code which uses the database Test-driven development General testing topics Unit-testing JavaScript How to …

How to make your code testable

Tags:

Image by Jim Frazier I’ve recently been working on a code-base which wasn’t designed with test-driven development methodologies, or with unit testing in mind. As I implemented unit-tests to this code, there were some modifications I had to do on the code. Some modifications popped up more than others. There were a few things that are more common than others …