Jan 22
2013

Test Driven Development in JavaScript using Jasmine

Test Driven Development (TDD) is a development process that suggests we write tests before we write our code to ensure that the code works as expected. While I’ve often read blog pieces praising the benefits of TDD, today was the first time I’ve really had a chance to experience it for myself.

At, Hack Reactor, we’ve been using Jasmine, a popular testing framework for JavaScript. It allows you to write ‘describe’ blocks which describe features being tested. Inside the describe blocks are are ‘it’ blocks that describe what we expect to happen under various circumstances.

The thing that made TDD fun today was that my pairing partner and I re-implemented a data structure we’d already written in a test-first process. Since we were only improving the performance of it, as opposed to changing its behavior, we could keep the original tests! When we ripped out the function all the tests turned red. Then when we finished a correct re-implementation not only was it time for high-fives, but we got the added joy of seeing all those ugly red failure boxes turn sweet, sweet, beautiful green.

On a side note, I have to say I’m amazed at the dedication of our teachers. Marcus was teaching us from morning until well past 10pm yesterday, on a Sunday, and spent nearly as many hours today, on his holiday. It’s absolutely jaw-dropping for someone with the kind of management and development responsibilities he has at Twitter! Shawn has also been powering through some sort of mega-cold and all other obstacles to keep us learning at top speed. Every one of them are animals!

This entry was tagged , , .
Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *