Enzyme is a JavaScript library for testing React components' output, and was developed by Airbnb. Enzyme has a really nice API for DOM manipulation and traversing. If you have used jQuery, it is really easy to understand the idea of the Enzyme API.
To start using Enzyme, perform the following steps:
- Install it by typing the following command in your Terminal. This will install the enzyme library and the adapter library for React version 16. There is an adapter available for older React versions:
npm install enzyme enzyme-adapter-react-16 --save-dev
- Create a new test file (test suite) called AddCar.test.js in the src folder. Now, we are going to create an Enzyme shallow rendering test for our AddCar component. The first test case renders the component and checks that there are five TextInput components, as there should be. wrapper.find finds every node in the...