DPS909 Lab 8 – Open Source Tooling and Automation

For this lab we extended our work from the previous lab to add unit testing. I decided to use Jest for the unit testing framework. It is a JavaScript tester that is created by Facebook.

Here is my GitHub repository for this lab: https://github.com/badrmodoukh/Seneca2017LearningLab

Steps I took to do this lab:

Doing this lab was straight-forward and I did not face any problems.

The first step I did was install Jest using the command npm install –save-dev jest. This installed Jest and saved it in the devDependency in the package.json file.

After I got Jest installed I created tests for the two functions I implemented in the last lab (isValidEmail() and formatSenecaEmail()).

I found creating tests for these two functions to be really useful. When I first implemented these functions I did not consider all the ways someone might use and misuse them. Creating tests for these functions allowed me to test them and improve them so that they can meet with the tests I did.

I created a test file name seneca.test.js which contains all of the tests.

The tests I did were for these scenarios:

for the isValidEmail():

  • testing a simple myseneca address
  • testing a non-myseneca address
  • user passes something other than a String to the function (ex. Number, Boolean)
  • user passes a variable which is actually null
  • email address contains leading whitespace
  • email address is for a professor vs. student (ex. ends with @senecacollege.ca)
  • email address uses old style Seneca address (ex. @senecac.on.ca)
  • string is empty

This is how the code looked for these tests:

Screen Shot 2017-03-28 at 2.04.43 PM.png

for the formatSenecaEmail():

  • adds @myseneca.ca to a simple string
  • adds @myseneca.ca to a string that contains spaces
  • user passes something other than a String to the function (ex. Number, Boolean)
  • user passes a variable which is actually null
  • string is empty

This how the code looks for these tests:

Screen Shot 2017-03-28 at 2.05.01 PM.png

Using describe() organized the code and grouped the tests together for each function. This made the code easier to read and follow.

I automated the tests by modifying the package.json file. I added a jest script and modified the test script to run lint and jest together.

This is how it looks:

Screen Shot 2017-03-28 at 2.11.20 PM.png


I believe unit testing is important to take into consideration when coding. It allows you to improve on your code and take into account how other people might use your code. I used unit testing in the past for Java with JUnit. I don’t remember much of it since it was a long time ago, but the general idea is similar. I found using Jest to be easier and more simple than when I used JUnit for Java in the past.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s