LEARNNode CLI Automation

Node Module Testing– Part #4

This is a six articles series for building and publishing a node module from scratch. You can find all these articles below:

Since our last testing, I have made a lot of changes. I refactored the code. I also added some looking background colors behinds the message type string. It's time to test our code again.

Testing The Module

I added two more alert types and I also changed a lot of code. So to test everything, I am going to check all the conditions. I have added the following in code in my test.js :

const alert = require('./index');
alert();
alert({ type: `success`, msg: `All done!` });
alert({ type: `warning`, msg: `You didn't add something!` });
alert({ type: `info`, msg: `Awais is awesome!` });
alert({ type: `error`, msg: `Something went wrong!` });

After I executed this code with npm test, my module ran and logged all the messages as you can see in the image below.

testing node module

Wrapping Up

Everything is working as expected. The node module is handling all the cases including the edge case when the user forgets to provide the options object.

Posted by Saad (It's a work in progress: Needs copy editing review by Awais.)