{"id":3729,"date":"2026-11-20T03:52:03","date_gmt":"2026-11-19T19:52:03","guid":{"rendered":"http:\/\/www.artemida-group.com\/blog\/?p=3729"},"modified":"2026-11-20T03:52:03","modified_gmt":"2026-11-19T19:52:03","slug":"how-to-use-enzyme-with-jest-400e-3a702a","status":"publish","type":"post","link":"http:\/\/www.artemida-group.com\/blog\/2026\/11\/20\/how-to-use-enzyme-with-jest-400e-3a702a\/","title":{"rendered":"How to use Enzyme with Jest?"},"content":{"rendered":"<p>If you\u2019ve 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\u2019ve 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\u2019m walking you through a practical, step-by-step guide that combines Enzyme\u2019s component testing superpowers with Jest\u2019s robust assertion and mocking tools\u2014no fluff, just what you need to make this work for your team. <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\/garcinia-cambogia-gummies97546.jpg\"><\/p>\n<p>First, let\u2019s get the basics out of the way so we\u2019re 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\u2014perfect 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\u2019s 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.<\/p>\n<p>Now, let\u2019s 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\u2014nice!) so there\u2019s no leftover configuration clutter. Open your terminal and run:<\/p>\n<p>npm install &#8211;save-dev enzyme jest enzyme-adapter-react-16<\/p>\n<p>Wait, why enzyme-adapter-react-16? Enzyme uses adapters to support different versions of React. If you\u2019re on React 17, you\u2019d install enzyme-adapter-react-17; React 18 uses enzyme-adapter-react-18, and so on. This is a common pitfall\u2014if your adapter doesn\u2019t 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:<\/p>\n<p>import { configure } from &#8216;enzyme&#8217;;<br \/>\nimport Adapter from &#8216;enzyme-adapter-react-16&#8217;;<\/p>\n<p>configure({ adapter: new Adapter() });<\/p>\n<p>That\u2019s the setup done\u2014way simpler than it used to be a few years ago, when you had to mess with webpack and Babel configs. Now let\u2019s write a test to see this in action. We\u2019ll use a simple React component, say a Button component that takes a label, an onClick handler, and a disabled prop. Here\u2019s what that component looks like:<\/p>\n<p>import React from &#8216;react&#8217;;<\/p>\n<p>const Button = ({ label, onClick, disabled }) =&gt; {<br \/>\nreturn (<br \/>\n<button onClick={onClick} disabled={disabled}><br \/>\n{label}<br \/>\n<\/button><br \/>\n);<br \/>\n};<\/p>\n<p>export default Button;<\/p>\n<p>Now, let\u2019s 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\u2019s 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\u2019s the test code:<\/p>\n<p>import React from &#8216;react&#8217;;<br \/>\nimport { shallow } from &#8216;enzyme&#8217;;<br \/>\nimport Button from &#8216;.\/Button&#8217;;<\/p>\n<p>describe(&#8216;Button Component&#8217;, () =&gt; {<br \/>\nit(&#8216;renders the correct label&#8217;, () =&gt; {<br \/>\nconst wrapper = shallow(&lt;Button label=&quot;Click Me&quot; onClick={() =&gt; {}} disabled={false} \/&gt;);<br \/>\nexpect(wrapper.text()).toBe(&#8216;Click Me&#8217;);<br \/>\n});<\/p>\n<p>it(&#8216;calls onClick when clicked&#8217;, () =&gt; {<br \/>\nconst mockOnClick = jest.fn();<br \/>\nconst wrapper = shallow(<Button label=\"Click Me\" onClick={mockOnClick} disabled={false} \/>);<br \/>\nwrapper.find(&#8216;button&#8217;).simulate(&#8216;click&#8217;);<br \/>\nexpect(mockOnClick).toHaveBeenCalledTimes(1);<br \/>\n});<\/p>\n<p>it(&#8216;is disabled when disabled prop is true&#8217;, () =&gt; {<br \/>\nconst wrapper = shallow(&lt;Button label=&quot;Click Me&quot; onClick={() =&gt; {}} disabled={true} \/&gt;);<br \/>\nexpect(wrapper.find(&#8216;button&#8217;).props().disabled).toBe(true);<br \/>\n});<br \/>\n});<\/p>\n<p>Let\u2019s break this down because each line serves a purpose. We use describe to group related tests, which keeps our test suite organized. For the first test, shallow renders only the Button component, so we don\u2019t have to worry about any parent or child components interfering. We use Jest\u2019s expect assertion to check that the text of the button is exactly what we passed in. The second test introduces Jest\u2019s mock function (jest.fn()), which lets us track if a function was called. We pass the mock onClick to the Button, use Enzyme\u2019s simulate method to trigger a click event on the button, then use Jest\u2019s toHaveBeenCalledTimes assertion to confirm the onClick fired once. The third test checks a prop value directly using Enzyme\u2019s props() method, which gives us access to all the props of the rendered element, and Jest\u2019s toBe assertion to confirm the disabled prop is true when we pass it.<\/p>\n<p>Now, what if we need to test a component that has child components? Shallow rendering won\u2019t render those children, so we need to use mount. Let\u2019s take a simple Form component that uses our Button:<\/p>\n<p>import React from &#8216;react&#8217;;<br \/>\nimport Button from &#8216;.\/Button&#8217;;<\/p>\n<p>const Form = ({ onSubmit }) =&gt; {<br \/>\nconst handleSubmit = (e) =&gt; {<br \/>\ne.preventDefault();<br \/>\nonSubmit();<br \/>\n};<\/p>\n<p>return (<\/p>\n<form onSubmit={handleSubmit}>\n<Button label=\"Submit\" onClick={handleSubmit} disabled={false} \/><br \/>\n<\/form>\n<p>\n);<br \/>\n};<\/p>\n<p>export default Form;<\/p>\n<p>If we used shallow to test this Form, it would only render the Form itself, not the Button, so we couldn\u2019t test the form\u2019s submit behavior properly. That\u2019s where mount comes in. Here\u2019s a test for the Form:<\/p>\n<p>import React from &#8216;react&#8217;;<br \/>\nimport { mount } from &#8216;enzyme&#8217;;<br \/>\nimport Form from &#8216;.\/Form&#8217;;<\/p>\n<p>it(&#8216;triggers onSubmit when form is submitted&#8217;, () =&gt; {<br \/>\nconst mockSubmit = jest.fn();<br \/>\nconst wrapper = mount(<Form onSubmit={mockSubmit} \/>);<br \/>\nwrapper.find(&#8216;form&#8217;).simulate(&#8216;submit&#8217;);<br \/>\nexpect(mockSubmit).toHaveBeenCalledTimes(1);<br \/>\n});<\/p>\n<p>This test renders the full DOM, so when we simulate a submit on the form, it triggers the handleSubmit function inside the Form, which calls our mock onSubmit. That\u2019s exactly what we want for integrating tests, where we care about how multiple components work together. A common mistake here is overusing mount\u2014shallow is better for isolated unit tests because it runs faster, while mount is for integration tests.<\/p>\n<p>Another powerful feature of Enzyme + Jest is mocking components and modules. Sometimes you have a component that imports a library or another component that\u2019s not the focus of your test. For example, if our Form uses a React DatePicker component, we don\u2019t want to test the DatePicker\u2019s behavior in our Form test\u2014we just want to make sure the DatePicker is rendered and that changes to it trigger the right functions. Jest makes mocking easy, and Enzyme lets us inspect how the mock is used. Let\u2019s adjust our Form to use DatePicker:<\/p>\n<p>import React from &#8216;react&#8217;;<br \/>\nimport Button from &#8216;.\/Button&#8217;;<br \/>\nimport DatePicker from &#8216;react-datepicker&#8217;;<\/p>\n<p>const Form = ({ onDateChange }) =&gt; {<br \/>\nreturn (<\/p>\n<div>\n<DatePicker onChange={onDateChange} \/><br \/>\n&lt;Button label=&quot;Submit&quot; onClick={() =&gt; {}} disabled={false} \/&gt;\n<\/div>\n<p>\n);<br \/>\n};<\/p>\n<p>export default Form;<\/p>\n<p>To test this, we can mock the react-datepicker module so our test doesn\u2019t pull in the actual DatePicker code (which would slow things down and add unnecessary complexity). Here\u2019s how that test looks:<\/p>\n<p>import React from &#8216;react&#8217;;<br \/>\nimport { mount } from &#8216;enzyme&#8217;;<br \/>\nimport Form from &#8216;.\/Form&#8217;;<br \/>\nimport DatePicker from &#8216;react-datepicker&#8217;;<\/p>\n<p>jest.mock(&#8216;react-datepicker&#8217;);<\/p>\n<p>it(&#8216;triggers onDateChange when DatePicker value changes&#8217;, () =&gt; {<br \/>\nconst mockDateChange = jest.fn();<br \/>\nconst wrapper = mount(<Form onDateChange={mockDateChange} \/>);<br \/>\n\/\/ Simulate a change on the DatePicker mock<br \/>\nwrapper.find(DatePicker).simulate(&#8216;change&#8217;, new Date(&#8216;2024-01-01&#8217;));<br \/>\nexpect(mockDateChange).toHaveBeenCalledWith(new Date(&#8216;2024-01-01&#8217;));<br \/>\n});<\/p>\n<p>Notice we mocked the DatePicker module with jest.mock, then when we simulate a change on our DatePicker instance, we pass a date value and check that the onDateChange mock was called with that exact date. This keeps our test focused on the Form\u2019s responsibility, not the DatePicker\u2019s.<\/p>\n<p>Now, let\u2019s talk about common mistakes teams run into when pairing Enzyme and Jest. The first is version mismatches between Enzyme adapter and React. I can\u2019t stress this enough\u2014Enzyme\u2019s adapters are tightly coupled to React versions, so if you\u2019re on React 18, using an adapter for React 17 will break your tests with errors like \u201cReact.createElement is not a function.\u201d Always double-check that your enzyme-adapter matches your installed React version. The second mistake is overusing shallow vs mount. Shallow is fast, great for unit tests of individual components, but if you need to test interactions between components, state updates that affect children, or DOM events, mount is the right choice. Using mount for every test will slow down your test suite significantly, so use it sparingly. The third mistake is not cleaning up between tests. When you use mount, Enzyme attaches components to the actual DOM by default, so if you don\u2019t unmount them after each test, you can get memory leaks or state bleed between tests. Jest runs tests in isolation, but Enzyme has a method for that: afterEach(() =&gt; wrapper.unmount()). I always recommend adding that to your test setup to keep things clean. The fourth mistake is not using Jest\u2019s mocking capabilities to their full potential. A lot of teams use Enzyme\u2019s find method to count child components, but if you\u2019re testing how a component uses an external library or another component, Jest mocks make those tests more reliable and focused on behavior, not implementation details.<\/p>\n<p>At the Enzyme tools division, we build utilities that make this workflow even smoother for teams of all sizes. We\u2019ve worked with startups with 5-person engineering teams to enterprise companies with hundreds of developers, and the biggest pain point we hear about is inconsistent test setup and flaky integration tests. Our pre-configured Enzyme + Jest starter kits come with pre-written setup files, common test patterns, and best practices tailored to different React versions, so teams don\u2019t have to spend hours debugging config issues. We also offer custom solutions for teams working on large applications with complex component trees, including tools for test coverage analysis specifically tuned for Enzyme render modes, so you can make sure you\u2019re testing every line of your component logic without wasting time on redundant tests.<\/p>\n<p>If your team is struggling with test suites that are too slow, flaky, or hard to maintain, we can help. We offer tailored assessments of your current test workflow, custom setup and integration of Enzyme with Jest, and ongoing support to adopt best practices that fit your team\u2019s needs. Whether you\u2019re a small team just getting started with testing or a large enterprise looking to scale your test suite without adding technical debt, our team of Enzyme and React testing experts can work with you to build a testing workflow that actually helps you ship better code faster.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.sentianherb.com\/uploads\/42606\/small\/silymarin-powder1c345.jpg\"><\/p>\n<p>Ready to stop fighting with test setup and start leveraging the power of Enzyme + Jest for your React projects? Reach out to our team to discuss your needs, and let\u2019s build a testing solution that works for your team.<\/p>\n<p><a href=\"https:\/\/www.sentianherb.com\/health-care-raw-material\/food-additive-raw-material\/amino-acid-powder\/\">Amino Acid Powder<\/a> REFERENCES<br \/>\nEnzyme Documentation, Jest Documentation, React Testing Best Practices (Enzyme Tools Division)<\/p>\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\u2019ve ever spent late nights debugging React component tests that feel more like guesswork than &hellip; <a title=\"How to use Enzyme with Jest?\" class=\"hm-read-more\" href=\"http:\/\/www.artemida-group.com\/blog\/2026\/11\/20\/how-to-use-enzyme-with-jest-400e-3a702a\/\"><span class=\"screen-reader-text\">How to use Enzyme with Jest?<\/span>Read more<\/a><\/p>\n","protected":false},"author":12,"featured_media":3729,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3692],"class_list":["post-3729","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-industry","tag-enzyme-4e21-3aad7b"],"_links":{"self":[{"href":"http:\/\/www.artemida-group.com\/blog\/wp-json\/wp\/v2\/posts\/3729","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.artemida-group.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.artemida-group.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.artemida-group.com\/blog\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"http:\/\/www.artemida-group.com\/blog\/wp-json\/wp\/v2\/comments?post=3729"}],"version-history":[{"count":0,"href":"http:\/\/www.artemida-group.com\/blog\/wp-json\/wp\/v2\/posts\/3729\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.artemida-group.com\/blog\/wp-json\/wp\/v2\/posts\/3729"}],"wp:attachment":[{"href":"http:\/\/www.artemida-group.com\/blog\/wp-json\/wp\/v2\/media?parent=3729"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.artemida-group.com\/blog\/wp-json\/wp\/v2\/categories?post=3729"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.artemida-group.com\/blog\/wp-json\/wp\/v2\/tags?post=3729"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}