TDD and JavaScript

I felt that I had to do this for my own good.:) To do TDD, the easiest way is to have nodeJS installed and up and running.

What I shortly did is to create my project skeleton

Then, you have to work in that folder

Create now two folders lib & test

Bring the package.json to your project by:

To do the testing, you will need mocha & chai

Now when everything is setup, lets start coding.
Suppose now that We have to implement the class Person, in which the method getFullName() will return concatenated firstName & lastName passed to the class constructor.

Create a test file and place it in the test folder. Also, create the person.js and place it in the lib folder.

Lets do the TDD now. The person.test.js may look like this for instance!?

To run the test:

The tests will fail for sure. Code your person.js in the lib folder:

Now, you have your first passed test case when running:

Now you are good to go with the rest. Read the documentation about chai & mocha and write your other test cases!