DEV Community

Neil An
Neil An

Posted on

Adding tests to my SSG

Hi everyone,

This week I added some testing tools to my SSG. The project now uses Jest for testing. I chose to use Jest because it is a very popular testing framework for JavaScript. I contemplated using Mocha, but after doing some research, decided Jest was easier to use out of the box. Installing Jest was easy. All I had to do was install it using npm: npm install --save-dev jest.

Writing the test cases on the other hand was more difficult. A lot of my tests didn't work as expected and I spent a lot of time figuring out how to use different types of matchers. I also had to change some of my existing code to handle some cases correctly. For example, if a function that handled text files was given a markdown file, then that function should throw an error or reject.

I learned a lot about testing. Even though I struggled a lot with writing tests, I can see the benefits of using tests, especially when you're working in a shared repository and you have to ensure that the code works.

Top comments (0)