3. Making assertions with Chai

the hand made image dedicated to the post number #{post.id}

Why Chai?

As mentioned in the structure, a test case goes red when anything in the it block throws an exception. First of all, by calling a function in specs we expect that it has been executed without any error. If the code seems to be pretty simple and writing specs for it sounds like a waste of time, it's still worth to have them, at least for this information.

2. The structure of a mocha test

the hand made image dedicated to the post number #{post.id}

As I said in the introduction you can select one of the various available interfaces. My favourite is BDD and this is the interface I'm going to present here. The main goal of this interface is to help you write specs as grammatically correct sentences.

1. An idea around specs

the hand made image dedicated to the post number #{post.id}

My intention is to create a practical guide to writing specs. More important than knowing how is knowing why to write specs.

Introduction to the BDD c(o)urse

the hand made image dedicated to the post number #{post.id}

As I wrote in the I do not write tests article, my favourite testing stack is Mocha with Sinon and Chai. Why? Each of the libraries is focused on a specific problem, they are highly customizable and their big community provides many add-ons and integrations. This makes them a truly universal stack.

I do not write tests

the hand made image dedicated to the post number #{post.id}

and i'm proud of it.

I've spent plenty years on coding, invested a lot of time in developing products, wrote thousands of lines of code and all that without writing a single unit test. I felt skilful, productive and effective at my job. Of course I made many mistakes, but as long as they were easy to fix I treated them as a side effect of my work.

It works, I promise

the hand made image dedicated to the post number #{post.id}

With javascript it's quite common to experience uncommon things. Sometimes it's about wrong parameters, something is undefined or we write totally invalid code using valid syntax. Moreover asynchronous code gives us headache when nesting goes beyond two or three levels.