Install Enzyme and Configure Jest

Tyler Clark
InstructorTyler Clark
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 4 years ago

In order to get up and going with Enzyme and Jest, some configurations are required. We will need to install some babel plugins, create a specific package json script, and depending on which version of Jest, add Jest configurations to our package.json.

Instructor: [00:00] In this course, I will be using Create React App as my background setup. Create React App comes with a lot of built-in configurations and installed dependencies that we need to get up and running with React Jest and Enzyme.

[00:12] If you're not using Create React App, you need to install as dev dependencies, Jest, babel-jest, babel-core, babel/preset-env, and babel/preset-react. Once our package is installed, we need to create a new file for our babelrc. We'll paste in our presets-env and react so that we can use ES6 and React and setup our test.

[00:35] Next, we need to make sure we have a script for actually running our test. Again, Create React App has this for us. However, one can simply just put Jest here, and that will our test as well.

[00:48] Also, if you [inaudible] Create React App, the Jest doc goes the detail on how to get it configured with Webpack, including how to handle select assets, CSS modules, and working with Webpack 2.

[01:00] With Jest configured, we can install as a dev dependency enzyme. Once this finishes, we will see it added to our package JSON.