Which is better for unit testing?

As I mentioned in my last blog post I am going to be testing my fairly big JavaScript application which is built with the Express web server framework. As with most things related to coding, there are lots of ways to go about testing your web application. The most sensible thing to do is use a testing framework or library, instead of writing them in vanilla JS which would take forever! A few that come to mind are Mocha, Chai, Jasmine and Jest (which I learnt about today). Jest is a testing suite for JavaScript applications, created by Facebook, and is the one I’ll be using. You can learn more at https://facebook.github.io/jest/

In addition to the above, there are many different types of tests I’ve heard of so far – end-to-end, logic, page, cross-page, link checking, integration, unit, etc. I’m no expert but I think unit testing is the way to go.

My journey started with Jasmine as the testing suite because that is the test suite you use on exercism.io. However, I had also read about Mocha and Chai together. Now I know Chai is not a test framework but rather a helpful library that can be integrated with a test framework of your choice. So this is definitely something I’ll be looking more into. My journey has now led me to use Jest because after lots of searching and asking questions, I never really found any good resources on how to unit test an Express app with Jasmine.

Most of the tutorials or blog posts I watched/read required that you ‘set up and teardown’ your express server before each and after each test. After running into lots of errors I decided to try a new framework – Jest, which was suggested by @zachcodes (a 10x software dev). When I found out it was Facebook’s test suite (which they use to test Facebook, obviously), I was certain it made sense. Anyway, I created a quick Gist on Github of how my test suite has begun (oh and it works! yay!)


The magic of Express.js

You know what I love about Node.js?  Express.js!

I’ve really been getting into Node.js lately, and I have not stopped enjoying it. I am building a fairly big application with Express.js and so far so good. Every month or two I get around to cleaning up the codebase and find myself feeling proud of it. I’m still learning more and more about Express.js, and this enables me to continuously be more organised and write cleaner code.

I get a kick out of how unopinionated it is. You structure it how you like, and that’s the beauty of it. It makes working with the backend a joy. I’ll always use Express.js and I will be an expert at it in a few years, I guarantee that.

I’d also like to put it out there that I will be learning about testing Express.js servers and about the best ways to secure your Express.js application. I will share my learnings here. More on this at a later date!