Into a Test-Driven Development with Nodejs, Mocha, and Chai

Published Mar 03, 2018Last updated Mar 07, 2018
Into a Test-Driven Development with Nodejs, Mocha, and Chai

image source:

About me

Call me enricks. I am an almost 3-year web developer. I have developed several customized web applications and most of them were made from scratch. I am a tech enthusiast, explorer, and problem solver.

Why I wanted to learn Into a Test-Driven Development with Nodejs, Mocha, and Chai

Most of the web application that I have implemented were build into a common way. This is where you code then you test the functionality, I survived that method but I am already tired of it. When there's a bug at the bank end, I really had to run through the process again without knowing if the there's an error syntactically or the processed data. Then question comes to my mind. is there a way where I can test all the back end first and check if the expected output is as what it is expected to be? So as I started a quick research, I came across with the Test-Driven development.

How I approached learning Into a Test-Driven Development with Nodejs, Mocha, and Chai

With this framework, I tried doing a simple API that is similar to login with Facebook functionality using Nodejs, mocha, and chai. There actually lot of nodejs package available for testing your script bit since mocha and chai are the most common use package, I decided to use them. Then I continue my research, looking and understanding the test script of some project that are available using the said technologies.

Challenges I faced

One of the challenges I did face while implementing the simple project using Test-Driven development framework is that I am tempted to write the code first before doing the test script. It is actually hard at first to visualize of how the functionalities will be implemented when you do the test script. It did sacrifice some time until I became use to it.

Key takeaways

One of the things that I could share some key points is that don't be afraid to go outside of your comfort zone and make your self suffer from your current situation. Sometimes, if the suffering happens daily and you get use to it, it will become your norm already that you don't even know you are actually making your self achieve things in a hard way. Be adventurous even in the realm of tech. It was really fun and sometimes frustrating doing something new but all of those was worth it.

Tips and advice

As I did finish the simple project, Test-Driven Development helps me in many ways: 1) it help me to set the acceptance criteria more clearly than before; 2) it actually helps me more to focus. It forces me to think in a smaller scale of functionality at a time rather than the application as a whole; 3) As I continue the implementation, it seems like as I run the unit test with fewer bugs since I can already test the back-end before going into the front-end; lastly 4) I got to spent less time in debugging error.

Final thoughts and next steps

Most of m Every experience on Test-Driven Development despite of the frustrations in the beginning. Everything was worth it, I will be using these framework more often for incoming projects. I guess my next step is to learn how to design best a best test script and go into advance level of it.

Discover and read more posts from Enrique Lacambra III
get started