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.

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.

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.

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.