Brief introduction about Jest Testing.

Advantages Of Jest

  • Provides useful features to test a single test or skip tests
  • Jest comes with an interactive mode that runs all the affected tests for the code changes that you’ve made in your last commit.
  • Provides documentation with numerous examples, also offers a CLI tool to control your tests easily.
  • Unit testing
  • Integration testing
  • UI testing

Setting up Jest

$ node -v
$ npm init -y
$ npm i --dev jest
$ npm i -g jsonserver
$ npm i axios

The package.json

"name": "jest-test",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "jest --verbose"
"keywords": [],
"author": "Jan Bodnar",
"license": "ISC",
"devDependencies": {
"jest": "^24.0.0"
"dependencies": {
"axios": "^0.18.0"

How do I know what to test?

  1. Import the function to test
  2. Give input to the function
  3. Define what to expect as the output
  4. Check if the function produces the expected output

Jest running tests

$ npm test> jest-test@1.0.0 test C:\Users\Jano\Documents\js\jest-test
> jest
PASS ./math-utils.test.js
PASS ./arith.test.js
PASS ./arith-params.test.js
PASS ./arith-skip.test.js
PASS ./string-utils.test.js
PASS ./arith-mock.test.js
PASS ./users.test.js
Test Suites: 7 passed, 7 total
Tests: 2 skipped, 35 passed, 37 total
Snapshots: 0 total
Time: 5.19s
Ran all test suites.
"test": "jest --verbose ./test-directory"




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The Best Way To Unsubscribe RxJS Observable In The Angular Applications!

How to Search a Word With Missing Letters

Tutorial: Kintsugi — how to contribute your Kusama to crowdloan

JS Interview: What is ‘this’?

Advanced JavaScript topics

Serverless Tutorial Solutions

rows of server machines in a descending rectangular arrangement

First look into Java Script

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nidhi Singh

Nidhi Singh

More from Medium

My experience with creating a Solid application


Why a High Code Coverage Is Nothing Worth and Leads Only to False Conclusions

YLD Perspectives: Mitchell Vivanti

Why should you program using TDD