First, we need to set up a testing engine to be able to run tests. In this book, we will use Jest (https://facebook.github.io/jest/). Jest, like React, is developed by the Facebook open source team. Perform the following steps to set up Jest:
- The first step is to install Jest via npm:
npm install --save-dev jest
npm install --save-dev babel-jest regenerator-runtime
If you use npm 3 or 4, or Yarn, you do not need to explicitly install regenerator-runtime.
- Next, we create a __tests__ directory in the project root. This is where we will put our test files.
- Then, we create a __tests__/example.test.js file, with the following code:
test('example test', () =>
expect(1 + 1).toBe(2)
- Finally, we define a test...