Getting ready

For Node, we had to install Jest on our own, but create-react-app already does that for us, so it's one less thing to worry about. (If you created the React application on your own, by writing your own configuration files then you should take a look at https://jestjs.io/docs/en/getting-started to see how to proceed.) We will, however, also use Enzyme, a package that will simplify making assertions about, or manipulating, the HTML that your components produce in a way that is quite similar to jQuery.

If you want to learn more about these functions, or if you haven't used jQuery for a while (my own case!), read about cheerio, the package that's used by Enzyme, at https://github.com/cheeriojs/cheerio. For Enzyme itself, including its configuration, you can visit its GitHub site at https://github.com/airbnb/enzyme.

Since we are using version 16 of React, the current way to install the package is as follows; the enzyme-adapter-react-16 additional package is needed to link Enzyme with React:

npm install enzyme enzyme-adapter-react-16 --save-dev

Another nice thing is that we won't need to do any particular configuration, because create-react-app also takes care of setting everything up. However, should you decide that you need something special, react-app-rewired will help: check out https://github.com/timarney/react-app-rewired for more on that.

We have everything we need; let's get testing!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.63.136