O'Reilly logo

Cross-platform Desktop Application Development: Electron, Node, NW.js, and React by Dmitry Sheiko

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing unit-tests

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required