Installing and running Jest
First, let's install the Jest command-line interface (Jest CLI) module:
npm install --save-dev jest
This command installs and adds the Jest module as a development dependency to our ~/snapterest/package.json
file.
In Chapter 2, Installing Powerful Tools for Your Project, we installed and discussed Babel. We use Babel to transpile our newer JavaScript syntax into the older JavaScript syntax, as well as compile JSX syntax into plain JavaScript syntax. In our tests, we'll be testing React components written in JSX syntax, but Jest doesn't understand JSX syntax out of the box. We need to tell Jest to automatically compile our tests with Babel. To do this, we need to install the babel-jest
module:
npm install --save-dev babel-jest
Now we need to configure Babel. To do this, create the following .babelrc
file in the ~/snapterest/
directory:
{ "presets": ["es2015", "react"]
Next, let's edit the package.json
file. We&apos...