DEV Community

Ritik Bheda
Ritik Bheda

Posted on

adding testing

This lab, i added testing to the ssg tool. I used Jest to test my tool. I choose Jest for testing as it is simple, and widely accepted. Also, documentation for it is very easy for beginners to understand and there is a huge community on the internet that shares knowledge on this framework if needed. The link to the official Jest website can be found here, link to its open source on GitHub can be found here.

Setting up Jest

to install Jest, you first need to install its npm package. most of the time it is preferred to install it as a dev-dependency as it is not the main part of developing. you can install it with this command.

npm i -D jest

then you need to update your package.json file to add a command to test all the test cases with one command. Adding this will work

"scripts": {
    "test": "jest"
  },
Enter fullscreen mode Exit fullscreen mode

I did have "aha!" moments while writing the test cases. one of them was, none of my function return a value. They all call another function on completion of a the work.

In the process, I gained much testing knowledge and coding as well as I had to edit my code in some places for better testing of the ssg. I have done testing before on my coop where we use mocha and chai for testing. they are similar to Jest framework but with some changes. I think I will be using Jest testing in my future projects I am thinking of developing a web-extension.

Oldest comments (0)