Introduction

I have recently started trying to add tests to my projects in order to understand how they work and to make sure my functions are returning what they should be. On my journey to learn more about how to implement testing, I discovered the Jest testing framework.

Getting Started

In order to start with Jest, you need to make sure it is saved as a dependency in your package.json . If your project does not have a package.json file already, in your terminal run:

npm init -y

This will initialize the package.json with the default values.

From here, we are going to add Jest to our package.json. In your terminal, write:

npm i --save-dev jest

We are going to save it as a dev dependency because we are only using it when we are developing our project.

Now, go inside of that package.json and under "scripts", where it says "tests" , write in: "jest" .

Image for post

To see if it is working, run: npm test

Image for post

You should see that it says ‘Test failed’, but that is because we haven’t written any tests or code to test against.

#javascript-tips #code #javascript #testing-tools #programming

Getting Started With Testing in JS
1.20 GEEK