{"id":3708,"date":"2026-11-19T13:45:44","date_gmt":"2026-11-19T05:45:44","guid":{"rendered":"http:\/\/www.arasdamco.com\/blog\/?p=3708"},"modified":"2026-11-19T13:45:44","modified_gmt":"2026-11-19T05:45:44","slug":"how-to-configure-enzyme-with-create-react-app-47cd-8da221","status":"publish","type":"post","link":"http:\/\/www.arasdamco.com\/blog\/2026\/11\/19\/how-to-configure-enzyme-with-create-react-app-47cd-8da221\/","title":{"rendered":"How to configure Enzyme with Create React App?"},"content":{"rendered":"<p>If you\u2019re building React applications with Create React App (CRA), you already have a powerful, streamlined workflow for development. But when it comes to testing component logic\u2014especially for dynamic UIs with state, props, and user interactions\u2014you need a tool that lets you render components, simulate events, and inspect outputs without spinning up a full browser. That\u2019s where Enzyme comes in. As a provider specializing in testing utilities for React ecosystems, I\u2019ve worked with dozens of teams that struggle to integrate Enzyme with their CRA setup, mostly because CRA\u2019s default test configuration can clash with third-party testing libraries. Over the years, I\u2019ve refined a step-by-step process that works for all modern CRA versions, and I\u2019m sharing it here so you can skip the trial and error. <a href=\"https:\/\/www.sentianherb.com\/health-care-raw-material\/enzyme\/\">Enzyme<\/a><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.sentianherb.com\/uploads\/42606\/small\/hair-vitamins-gummies-15535b6.png\"><\/p>\n<p>First, let\u2019s clear up a common misconception: Enzyme isn\u2019t the only testing library for React, but it\u2019s one of the most flexible for teams that need granular control over component behavior. Unlike React Testing Library (which prioritizes user-centric testing), Enzyme gives you APIs like <code>shallow<\/code> (for isolated component rendering), <code>mount<\/code> (for full DOM rendering), and <code>render<\/code> (for static HTML output) that make it easy to test edge cases\u2014like ensuring a child component passes props correctly, or that a click handler updates state as expected. For teams that rely on these low-level checks, integrating Enzyme with CRA is non-negotiable.<\/p>\n<h3>Step 1: Check Your CRA and Enzyme Versions<\/h3>\n<p>Before you install anything, confirm you\u2019re using compatible versions. CRA v3 and above use React 16.8+, and Enzyme v3 is the minimum required for React 16 compatibility. For React 18 projects, you\u2019ll need Enzyme v3.11 or newer, as older versions don\u2019t support React 18\u2019s concurrent rendering features. If you\u2019re working on an older CRA project (pre-v3), you\u2019ll need to eject your configuration first, but I\u2019ll focus on the default zero-config CRA setup that works for 90% of teams today.<\/p>\n<h3>Step 2: Install Dependencies Correctly<\/h3>\n<p>A lot of teams mess up installation by skipping peer dependencies, which leads to weird runtime errors. To avoid that, install Enzyme along with its required adapter for your React version, plus Jest\u2019s Enzyme integration (since CRA uses Jest under the hood):<\/p>\n<pre><code class=\"language-bash\">npm install --save-dev enzyme @wojtekmaj\/enzyme-adapter-react-17 enzyme-to-json\n<\/code><\/pre>\n<p>Wait\u2014why <code>@wojtekmaj\/enzyme-adapter-react-17<\/code> instead of the official <code>enzyme-adapter-react-17<\/code>? The official adapter stopped being maintained after React 17, and the community-driven version is the only one that works reliably with CRA v5 and newer. If you\u2019re on React 18, use <code>@wojtekmaj\/enzyme-adapter-react-18<\/code> instead. And <code>enzyme-to-json<\/code>? That\u2019s a helper that lets you convert Enzyme\u2019s output to a format Jest can snapshot, which is critical for keeping your tests readable and maintainable.<\/p>\n<h3>Step 3: Configure Enzyme for Jest (CRA\u2019s Test Runner)<\/h3>\n<p>CRA automatically sets up Jest, but you need to tell Jest to use your Enzyme adapter so it knows how to render React components. The best place to do this is in a <code>setupTests.js<\/code> file in your <code>src<\/code> directory\u2014this is a special file CRA runs before every test, so it\u2019s the perfect spot for one-time configurations. Create the file if it doesn\u2019t exist, and add this code:<\/p>\n<pre><code class=\"language-javascript\">import Enzyme from 'enzyme';\nimport Adapter from '@wojtekmaj\/enzyme-adapter-react-17';\nimport { createSerializer } from 'enzyme-to-json';\n\n\/\/ Configure Enzyme with the adapter for your React version\nEnzyme.configure({ adapter: new Adapter() });\n\n\/\/ Add enzyme-to-json as a Jest serializer for clean snapshots\nexpect.addSnapshotSerializer(createSerializer({ mode: 'deep' }));\n<\/code><\/pre>\n<p>That\u2019s it for the core configuration. No need to edit any other CRA files, no ejecting, no complicated Babel or Jest tweaks. This works out of the box with CRA\u2019s default setup because CRA\u2019s <code>setupTests.js<\/code> is automatically included in the test run process.<\/p>\n<h3>Step 4: Write Your First Enzyme Test<\/h3>\n<p>Now let\u2019s test a real component to make sure everything works. Let\u2019s say you have a simple <code>Button<\/code> component in <code>src\/components\/Button.js<\/code>:<\/p>\n<pre><code class=\"language-javascript\">import React from 'react';\n\nconst Button = ({ label, onClick }) =&gt; {\n  return (\n    &lt;button className=&quot;custom-button&quot; onClick={onClick}&gt;\n      {label}\n    &lt;\/button&gt;\n  );\n};\n\nexport default Button;\n<\/code><\/pre>\n<p>To test it with Enzyme, create a <code>Button.test.js<\/code> file in the same directory:<\/p>\n<pre><code class=\"language-javascript\">import React from 'react';\nimport { shallow, mount } from 'enzyme';\nimport Button from '.\/Button';\n\n\/\/ Test 1: Shallow render (isolated, no child components)\ntest('renders button with correct label', () =&gt; {\n  const wrapper = shallow(&lt;Button label=&quot;Click Me&quot; \/&gt;);\n  expect(wrapper.text()).toBe('Click Me');\n  expect(wrapper.hasClass('custom-button')).toBe(true);\n});\n\n\/\/ Test 2: Simulate a click event\ntest('calls onClick when button is clicked', () =&gt; {\n  \/\/ Create a mock function to track if onClick is called\n  const mockOnClick = jest.fn();\n  const wrapper = shallow(&lt;Button label=&quot;Click Me&quot; onClick={mockOnClick} \/&gt;);\n  \n  \/\/ Simulate a click on the button\n  wrapper.find('button').simulate('click');\n  \n  \/\/ Verify the mock function was called once\n  expect(mockOnClick).toHaveBeenCalledTimes(1);\n});\n\n\/\/ Test 3: Full DOM render (for components that need child interactions)\ntest('renders full component with children', () =&gt; {\n  \/\/ Use mount instead of shallow to render all child components\n  const wrapper = mount(&lt;Button label=&quot;Submit&quot; \/&gt;);\n  expect(wrapper.getDOMNode().textContent).toBe('Submit');\n});\n<\/code><\/pre>\n<p>Run <code>npm test<\/code> in your terminal, and all three tests should pass. If you get an error here, it\u2019s almost always because you installed the wrong adapter or forgot to configure the <code>setupTests.js<\/code> file\u2014double-check those two steps before digging into more complex fixes.<\/p>\n<h3>Step 5: Troubleshoot Common CRA + Enzyme Issues<\/h3>\n<p>Even with a correct setup, you might run into one of these common problems. Let\u2019s walk through how to fix them quickly:<\/p>\n<ol>\n<li><strong>\u201cEnzyme Internal Error: Unable to find node on the passed type\u201d<\/strong>: This usually happens if you\u2019re using shallow render and trying to find a child component. Remember, <code>shallow<\/code> only renders the component itself, not its children. Either use <code>mount<\/code> for full DOM rendering, or update your test to target a node on the parent component.<\/li>\n<li><strong>Snapshot test formatting is messy<\/strong>: If your Jest snapshots include extra React internals, make sure you added <code>enzyme-to-json<\/code> as a serializer in <code>setupTests.js<\/code>. Without that, Enzyme\u2019s output won\u2019t cleanly serialize for snapshots.<\/li>\n<li><strong>React 18 hydration errors in mount tests<\/strong>: React 18\u2019s new root API can cause issues with <code>mount<\/code> in older Enzyme adapters. If you\u2019re on React 18, switch to <code>@wojtekmaj\/enzyme-adapter-react-18<\/code> and make sure your test code doesn\u2019t rely on <code>ReactDOM.render<\/code> (use <code>mount<\/code> instead, which works with React 18\u2019s root).<\/li>\n<\/ol>\n<h3>Why This Setup Works for CRA Teams<\/h3>\n<p>CRA is designed to reduce friction for new React developers, but its default testing setup is limited. Enzyme fills that gap by giving teams the tools to test not just what users see, but how components behave under the hood. Whether you\u2019re testing state changes, prop passing, or event handlers, the configuration I outlined above is lightweight, doesn\u2019t require ejecting, and works with all standard CRA workflows.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.sentianherb.com\/uploads\/42606\/small\/l-5-mthf-calcium-powder3dce8.jpg\"><\/p>\n<p>As a provider of testing solutions for React development, we work with teams large and small to tailor Enzyme setups to their specific CRA projects. Whether you\u2019re troubleshooting a tricky test case, looking to optimize your test suite\u2019s performance, or need help integrating Enzyme with other tools like Cypress or Storybook, we can provide the support you need to get up and running quickly.<\/p>\n<p><a href=\"https:\/\/www.sentianherb.com\/health-care-raw-material\/colorant\/\">Food Colorant<\/a> If your team is looking to implement robust component testing with Enzyme for your Create React App projects, or if you need to refine your existing test workflow, get in touch with us to discuss your requirements. We can provide custom configuration guidance, testing best practices, and scalable solutions that fit your team\u2019s size and tech stack.<\/p>\n<h3>References<\/h3>\n<ol>\n<li>Enzyme Official Documentation, https:\/\/enzymejs.github.io\/enzyme\/<\/li>\n<li>Create React App Testing Guide, https:\/\/create-react-app.dev\/docs\/running-tests\/<\/li>\n<li>enzyme-to-json Repository, https:\/\/github.com\/adriantoine\/enzyme-to-json<\/li>\n<\/ol>\n<hr>\n<p><a href=\"https:\/\/www.sentianherb.com\/\">Xi&#8217;an Sentian Biotechnology Co., Ltd.<\/a><br \/>Xi&#8217;an Sentian Biotechnology Co., Ltd. is one of the most professional enzyme manufacturers and suppliers in China, specialized in providing high quality customized service and OEM&#038;ODM private label service. Be free to wholesale bulk enzyme in stock here from our factory. Contact us for free sample.<br \/>Address: Jingfa Building, No. 132 Weiyang Road, Weiyang District, Xi&#8217;an City, Shaanxi Province<br \/>E-mail: sales3@sentianbio.com<br \/>WebSite: <a href=\"https:\/\/www.sentianherb.com\/\">https:\/\/www.sentianherb.com\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you\u2019re building React applications with Create React App (CRA), you already have a powerful, streamlined &hellip; <a title=\"How to configure Enzyme with Create React App?\" class=\"hm-read-more\" href=\"http:\/\/www.arasdamco.com\/blog\/2026\/11\/19\/how-to-configure-enzyme-with-create-react-app-47cd-8da221\/\"><span class=\"screen-reader-text\">How to configure Enzyme with Create React App?<\/span>Read more<\/a><\/p>\n","protected":false},"author":807,"featured_media":3708,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3671],"class_list":["post-3708","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-industry","tag-enzyme-45e2-8de2c2"],"_links":{"self":[{"href":"http:\/\/www.arasdamco.com\/blog\/wp-json\/wp\/v2\/posts\/3708","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.arasdamco.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.arasdamco.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.arasdamco.com\/blog\/wp-json\/wp\/v2\/users\/807"}],"replies":[{"embeddable":true,"href":"http:\/\/www.arasdamco.com\/blog\/wp-json\/wp\/v2\/comments?post=3708"}],"version-history":[{"count":0,"href":"http:\/\/www.arasdamco.com\/blog\/wp-json\/wp\/v2\/posts\/3708\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.arasdamco.com\/blog\/wp-json\/wp\/v2\/posts\/3708"}],"wp:attachment":[{"href":"http:\/\/www.arasdamco.com\/blog\/wp-json\/wp\/v2\/media?parent=3708"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.arasdamco.com\/blog\/wp-json\/wp\/v2\/categories?post=3708"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.arasdamco.com\/blog\/wp-json\/wp\/v2\/tags?post=3708"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}