Painless JavaScript testing with Jest
The most important way to learn how to test React components in the right way is by writing some code, and that is what we are going to do in this section.
The React documentation says that at Facebook they use Jest to test their components. However, React does not force you to use a particular test framework and you can use your favorite one without any problems.
In the next section, you will learn how it's possible to test components using Mocha.
To see Jest in action we are going to create a project from scratch, installing all the dependencies and writing a component with some tests. It'll be fun!
The first thing to do is to move into a new folder and run:
npm init
Once the package.json
is created we can ...
Get React Design Patterns and Best Practices now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.