To write tests for our React code, we need to first install some libraries for running tests and writing assertions. In this lesson we walk through setting up Mocha as our test runner and
expect as our assertion library. We will also set up some React and JSX specific test tools (React Test Utils) to make writing our tests easier.
NOTE: There are many alternatives to Mocha, expect, and the other test tools we use in this course. Although we use these specific tools and libraries, the testing principles apply to all other tools.
Before we write tests for our React components, we're going to need a test runner. I'm going to NPM install Mocha. We also need to be able to write assertions for our tests, so I'm going to install the Expect library. Finally, we're going to need the React addons TestUtils package, which has been developed by the React team to make it easier to test React components.
I'm going to add the -save-dev flag onto this command, so that it saves these packages into our package.json devDependencies. We'll run this, and we can see in our package.json that the dependencies have been installed, as expected.
We're now set up to write up some tests. I'd like to point out that, although we're using Mocha and Expect, there are many test tools that you can use, but the principles in this course apply to all these different test tools.