Posted in

How to use Enzyme with Jest?

If you’ve ever spent late nights debugging React component tests that feel more like guesswork than quality assurance, you know how frustrating it can be. As a lead at the Enzyme tools division, I’ve helped hundreds of development teams move from flaky, unmaintainable test suites to ones that actually help them ship faster and with more confidence. One of the most common questions we get is: how to pair Enzyme with Jest to get the best of both tools? Today, I’m walking you through a practical, step-by-step guide that combines Enzyme’s component testing superpowers with Jest’s robust assertion and mocking tools—no fluff, just what you need to make this work for your team. Enzyme

First, let’s get the basics out of the way so we’re all on the same page. Enzyme, for those new to it, is a testing utility library built specifically for React (and React-like) components. It lets you render components, interact with them, and inspect their output in three different render modes: shallow, mount, and render. Shallow rendering renders only the component itself, not its child components—perfect for isolating unit tests. Mount rendering does a full DOM render, including child components, so you can test interactions like clicks or form submissions. Render uses React’s server-side rendering (SSR) output to generate static HTML, great for checking structural elements without worrying about event handlers. Jest, on the other hand, is a full-featured JavaScript testing framework that includes a test runner, assertion library, mocking utilities, and coverage reporting built right in. Pairing them is a natural fit: Jest handles the overall test workflow, and Enzyme handles the component-specific rendering and inspection.

Now, let’s dive into the setup. The first step is making sure you have the right dependencies installed in your React project. I always recommend starting with a clean project (or adding these to an existing one using Create React App, which actually has Jest built in by default—nice!) so there’s no leftover configuration clutter. Open your terminal and run:

npm install –save-dev enzyme jest enzyme-adapter-react-16

Wait, why enzyme-adapter-react-16? Enzyme uses adapters to support different versions of React. If you’re on React 17, you’d install enzyme-adapter-react-17; React 18 uses enzyme-adapter-react-18, and so on. This is a common pitfall—if your adapter doesn’t match your React version, your tests will throw cryptic errors about invalid render methods. Once those are installed, you need to configure Enzyme to use the adapter in your Jest setup. Create a file called setupTests.js in your src folder (Create React App looks for this file automatically, which saves you from editing multiple config files). Inside, add:

import { configure } from ‘enzyme’;
import Adapter from ‘enzyme-adapter-react-16’;

configure({ adapter: new Adapter() });

That’s the setup done—way simpler than it used to be a few years ago, when you had to mess with webpack and Babel configs. Now let’s write a test to see this in action. We’ll use a simple React component, say a Button component that takes a label, an onClick handler, and a disabled prop. Here’s what that component looks like:

import React from ‘react’;

const Button = ({ label, onClick, disabled }) => {
return (

);
};

export default Button;

Now, let’s write a Jest + Enzyme test for this Button component. Create a file called Button.test.js in the same folder. First, import the tools we need: Jest’s expect, shallow from Enzyme, and our Button component. The test will cover three key behaviors: rendering the correct label, calling the onClick handler when clicked, and disabling the button when the disabled prop is true. Here’s the test code:

import React from ‘react’;
import { shallow } from ‘enzyme’;
import Button from ‘./Button’;

describe(‘Button Component’, () => {
it(‘renders the correct label’, () => {
const wrapper = shallow(<Button label="Click Me" onClick={() => {}} disabled={false} />);
expect(wrapper.text()).toBe(‘Click Me’);
});

it(‘calls onClick when clicked’, () => {
const mockOnClick = jest.fn();
const wrapper = shallow(