Member-only story
An Introduction to Jest JavaScript Testing Framework
An open source testing toolkit that works on most JavaScript projects

The topic for today is Jest, a JavaScript testing framework which comes in handy for testing your JavaScript projects. At the time of this writing, it comes with great support for Babel, TypeScript, Node, React, Angular, Vue, and a lot more.
According to the official documentation, it provides the following functionalities:
- fast and safe
- code coverage
- easy mocking
- great exceptions
Jest is a great testing toolkit for developers who are looking for other alternatives and have experience with the following testing frameworks:
- AVA
- Expect.js
- Jasmine
- Mocha
- proxyquire
- Should.js
- Tape
Let’s proceed to the next section and start installing Jest.
Setup
Installation is pretty straightforward via either yarn or npm, based on your own preferences.
yarn
Install Jest via yarn as follows:
yarn add --dev jest
npm
Alternatively, you can use npm to install Jest as well.
npm install --save-dev jest
JavaScript files
Let’s create two new JavaScript files as part of the test:
algebra.js
algebra.test.js
Files that end with .test.js
will be part of the testing suites in Jest. You can just create more test files and Jest will automatically include them in the test.
Configuration
If you are starting afresh in a new folder, run the following command to create a new package.json
file.
npm init
Then modify or include the following inside package.json
{
"scripts": {
"test": "jest"
}
}