In real life, we cover application functionality with unit-tests. When it comes to React, the Jest testing framework is the first to pop up in one's mind. The framework is developed by Facebook as well as React. Jest is not aimed at React only; you can test any JavaScript. Just to see how it works, we can set up a new project:
npm init -y
Install Jest by running the following command:
npm i -D jest
Edit the scripts section in package.json:
"scripts": { "test": "jest" }
Place the example unit for testing:
./unit.js
function double( x ){ return x * 2;}exports.double = double;
This is a simple pure function that double any given number. What we need to do now is to just place a JavaScript file of a name matching ...