{"id":734,"date":"2026-11-19T16:24:19","date_gmt":"2026-11-19T08:24:19","guid":{"rendered":"http:\/\/www.algodehumor.com\/blog\/?p=734"},"modified":"2026-11-19T16:24:19","modified_gmt":"2026-11-19T08:24:19","slug":"how-to-test-if-a-component-receives-a-prop-with-enzyme-4302-343e23","status":"publish","type":"post","link":"http:\/\/www.algodehumor.com\/blog\/2026\/11\/19\/how-to-test-if-a-component-receives-a-prop-with-enzyme-4302-343e23\/","title":{"rendered":"How to test if a component receives a prop with Enzyme?"},"content":{"rendered":"<p>Hey folks, let\u2019s cut to the chase\u2014if you\u2019ve spent any time building React components, you\u2019ve run into that split second where you wonder, \u201cDid this thing even get the prop I passed it?\u201d It\u2019s not just a tiny question either; missing a prop can break forms, hide features, or throw wonky errors that take hours to hunt down. And if you\u2019re using Enzyme to test those components (which, full transparency, is the tool my team supplies\u2014we\u2019ve got years of feedback from devs just like you dealing with this exact headache), then there are solid, repeatable ways to confirm your props are landing exactly where they should. <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\/lutein-softgels2a9d5.jpg\"><\/p>\n<p>I\u2019ve seen too many devs fumble through this: they\u2019ll mock a prop, fire up a test, and cross their fingers, only to realize the prop never got passed because they named it wrong, or they nested it too deep in a component tree, or even that the component itself is doing something dumb with default props that overrides their test data. Today, I\u2019m walking through the methods that actually work, not the outdated stuff you might see in old blog posts, with real examples I\u2019ve pulled from client projects we\u2019ve supported.<\/p>\n<p>First, let\u2019s set the stage. When we talk about a component receiving a prop, that\u2019s not just about the top-level props you pass when you render the component\u2014it\u2019s about whether that prop is available at the exact part of the component where you need it. For example, if you have a UserAvatar component that takes a <code>user<\/code> prop, you don\u2019t just care that you passed <code>user={{ name: &quot;Mia&quot;, avatar: &quot;mia-pic.jpg&quot; }}<\/code> when rendering UserAvatar; you care that inside UserAvatar, the Avatar sub-component is actually getting that <code>avatar<\/code> URL, not some hardcoded default. Enzyme makes this way easier than trying to query the DOM for hidden data attributes, but you have to use the right methods, not just <code>.state()<\/code> or <code>.find()<\/code>.<\/p>\n<p>Let\u2019s start with the basics: shallow rendering. If you\u2019re unit testing a component, shallow render is non-negotiable\u2014this renders only the component you\u2019re testing, not its children, so you don\u2019t have to dig through multiple layers to check for props. Let\u2019s use a simple example: a Button component that takes a <code>disabled<\/code> prop. Suppose your component code looks like this:<\/p>\n<pre><code class=\"language-jsx\">const SubmitButton = ({ disabled, label }) =&gt; {\n  return &lt;button disabled={disabled}&gt;{label}&lt;\/button&gt;;\n};\n<\/code><\/pre>\n<p>A lot of devs will write a test that does something like this:<\/p>\n<pre><code class=\"language-javascript\">test('Button receives disabled prop', () =&gt; {\n  const wrapper = shallow(&lt;SubmitButton disabled={true} label=&quot;Submit&quot; \/&gt;);\n  expect(wrapper.props('disabled')).toBe(true);\n});\n<\/code><\/pre>\n<p>Wait\u2014does that work? No, actually. I see this mistake all the time. The <code>.props()<\/code> method returns the full props object of the root node of the shallow render, not a single prop when you pass an argument. That test would throw an error, or if you fix it to <code>wrapper.props().disabled<\/code>, that works for this simple case, but it falls apart when you\u2019re testing deeper props, especially with full DOM rendering or mount.<\/p>\n<p>The correct approach for shallow, top-level props is to use <code>.prop()<\/code>\u2014yes, singular, not plural. <code>.prop()<\/code> takes a string of the prop name, and it returns the value of that prop on the root node of your wrapper. So fixing that test:<\/p>\n<pre><code class=\"language-javascript\">test('shallow renders receives disabled prop', () =&gt; {\n  const wrapper = shallow(&lt;SubmitButton disabled={true} label=&quot;Submit&quot; \/&gt;);\n  expect(wrapper.prop('disabled')).toBe(true);\n});\n<\/code><\/pre>\n<p>That\u2019s solid for shallow, top-level props. But what if your component has children, and you need to check that a child component received a prop? Let\u2019s adjust our example: the SubmitButton might wrap a custom Icon component, like this:<\/p>\n<pre><code class=\"language-jsx\">const SubmitButton = ({ disabled, label }) =&gt; {\n  return (\n    &lt;button disabled={disabled}&gt;\n      &lt;Icon name=&quot;submit&quot; disabled={disabled} \/&gt;\n      {label}\n    &lt;\/button&gt;\n  );\n};\n<\/code><\/pre>\n<p>Now, if we want to confirm that the Icon component got the <code>disabled<\/code> prop, <code>.prop()<\/code> on the root node won\u2019t work\u2014we need to find the Icon first. Enter the <code>.find()<\/code> method. With shallow rendering, <code>shallow(&lt;SubmitButton \/&gt;).find(Icon)<\/code> will return a wrapper for just the Icon component, and then we can call <code>.prop()<\/code> on that wrapper. So the test becomes:<\/p>\n<pre><code class=\"language-javascript\">test('Icon child receives disabled prop', () =&gt; {\n  const wrapper = shallow(&lt;SubmitButton disabled={true} label=&quot;Submit&quot; \/&gt;);\n  const iconWrapper = wrapper.find(Icon);\n  expect(iconWrapper.prop('disabled')).toBe(true);\n});\n<\/code><\/pre>\n<p>This is where a lot of people trip up: if you forget to call <code>.find()<\/code> to target the child, you\u2019ll accidentally check the button\u2019s <code>disabled<\/code> prop instead of the Icon\u2019s. And if your test is failing here, don\u2019t just assume your prop is missing\u2014double-check that your component is actually passing that prop to the child. We\u2019ve had a client a few months back who spent three hours debugging a test like this only to realize they\u2019d typed <code>disable<\/code> instead of <code>disabled<\/code> in the component, so the test was working, just the component wasn\u2019t. That\u2019s why testing prop flow is as much about your component logic as it is about your test code.<\/p>\n<p>Now, what about full DOM rendering with <code>mount()<\/code>? Shallow rendering skips child components entirely, which is great for unit tests, but if you\u2019re doing integration tests that need to test how props work across your entire component tree\u2014say, if the SubmitButton gets its <code>disabled<\/code> prop from a parent Form component\u2014you\u2019ll use <code>mount()<\/code>. Let\u2019s say our parent Form passes <code>disabled<\/code> to SubmitButton, which we pass to Icon. With mount, the process is almost the same, but wait\u2014there\u2019s a caveat here. When you use mount, Enzyme renders the full DOM, so you can also check props on HTML elements if that\u2019s what you need, but for custom components, the same <code>.find()<\/code> + <code>.prop()<\/code> pattern applies. Let\u2019s test the parent prop flow:<\/p>\n<pre><code class=\"language-javascript\">test('Icon receives disabled prop from parent Form', () =&gt; {\n  const wrapper = mount(\n    &lt;Form initialValues={{}}&gt;\n      &lt;SubmitButton label=&quot;Submit&quot; \/&gt;\n    &lt;\/Form&gt;\n  );\n  \/\/ First, find SubmitButton, then find Icon inside it\n  const iconWrapper = wrapper.find(SubmitButton).find(Icon);\n  expect(iconWrapper.prop('disabled')).toBe(true); \/\/ If Form disables when there are unsaved changes, this passes\n});\n<\/code><\/pre>\n<p>Wait, but what if you\u2019re using TypeScript? A lot of our clients use TypeScript, and they run into issues where <code>.prop()<\/code> returns type <code>any<\/code>, which can break type checks. No sweat\u2014there\u2019s a fix. If you know the type of the prop you\u2019re testing, you can add a type assertion, or even better, use <code>shallowWithTypes<\/code> if you\u2019re using TypeScript 4+ and our Enzyme-compatible tools, which we built specifically to handle those edge cases. That\u2019s one of the perks our users mention most\u2014we don\u2019t just supply the core Enzyme library, we add the small, quality-of-life utilities that fix the stuff that\u2019s a pain point for devs.<\/p>\n<p>Another common scenario: default props. A lot of components have default props set with <code>defaultProps<\/code>, so you might be wondering, \u201cIf I don\u2019t pass a prop, should my test check for the default value?\u201d Let\u2019s clarify: if your test is checking that the component receives a prop you explicitly passed, then default props don\u2019t matter. But if you\u2019re testing that the component falls back to a default when no prop is passed, then <code>.prop()<\/code> will correctly return the default value. Wait, let\u2019s confirm that with an example. Suppose our Icon component has a default prop for <code>disabled<\/code>:<\/p>\n<pre><code class=\"language-jsx\">Icon.defaultProps = {\n  disabled: false,\n};\n<\/code><\/pre>\n<p>If we render Icon without passing <code>disabled<\/code>, and call <code>iconWrapper.prop('disabled')<\/code>, it will return <code>false<\/code>\u2014that\u2019s correct. But if we pass <code>disabled={true}<\/code>, it returns <code>true<\/code>, which is also correct. So that\u2019s an important distinction: if your test is verifying that a prop you explicitly passed is received, you\u2019re good to go. If it\u2019s verifying default prop behavior, that works too.<\/p>\n<p>Wait, what about static props? Like if you have a component that uses <code>static propTypes<\/code> to validate props? Enzyme doesn\u2019t replace propTypes validation, but if you want to test that a component is receiving a prop that matches its propTypes, you can use the <code>.instance()<\/code> method to get the component instance, and check its <code>props<\/code> directly. For example:<\/p>\n<pre><code class=\"language-javascript\">test('prop type validation works for received props', () =&gt; {\n  const wrapper = shallow(&lt;SubmitButton label=&quot;Test&quot; disabled={true} \/&gt;);\n  const instance = wrapper.instance();\n  expect(instance.props.disabled).toBe(true);\n  \/\/ If you pass a wrong prop type, like disabled as a string, React will throw a console warning, which you can test with jest.mock to capture\n});\n<\/code><\/pre>\n<p>That\u2019s useful if you want to ensure that not only is the prop there, but it\u2019s the right type. Our clients often combine this with their test suites to catch prop type bugs before they make it to production.<\/p>\n<p>Now, let\u2019s talk about common pitfalls to avoid, because even with Enzyme, it\u2019s easy to mess up. First, don\u2019t use the <code>.state()<\/code> method to check props\u2014<code>.state()<\/code> is for internal component state, not props. I see this all the time: a dev will call <code>wrapper.state('disabled')<\/code> expecting the prop, and it will always be undefined, because state and props are separate. Second, don\u2019t rely on text in the DOM to test props\u2014just because a button has the text \u201cSubmit\u201d doesn\u2019t mean it got the <code>label<\/code> prop; the text could be hardcoded. Third, when using <code>.find()<\/code>, make sure you\u2019re targeting the right component name. If you have two Icon components, or a named export vs a default export, Enzyme\u2019s <code>.find()<\/code> can have issues if you\u2019re not using the correct import path. For example, if your component is <code>export const Icon = () =&gt; {}<\/code>, you need to import it as <code>import { Icon }<\/code> in your test, not as <code>import Icon<\/code>, otherwise <code>wrapper.find(Icon)<\/code> won\u2019t work. That\u2019s a small gotcha, but it trips up even senior devs sometimes.<\/p>\n<p>Another edge case: functional components with hooks. If you\u2019re testing a component that uses React hooks like <code>useState<\/code> or <code>useContext<\/code>, does that change how you test props? No, actually. The <code>.prop()<\/code> and <code>.find()<\/code> methods work exactly the same, because hooks don\u2019t alter how props are passed to the component. The only difference is that if you\u2019re using <code>mount()<\/code>, you\u2019ll want to make sure your test is wrapped in any context providers your component uses, just like your app is. Our Enzyme tools include pre-built context wrappers for common libraries like React Router and Formik, which saves our clients hours of setting up test environments.<\/p>\n<p>Let\u2019s circle back to why this matters. Testing that components receive props isn\u2019t just a \u201cnice-to-have\u201d \u2014 it\u2019s part of building reliable UIs. If you don\u2019t confirm props are passing correctly, you might end up with a button that\u2019s supposed to be disabled but isn\u2019t, a user avatar that shows the wrong picture, or a form that submates the wrong data. The methods I\u2019ve walked through are all battle-tested with our clients, who use these same approaches in their production test suites. And since we supply Enzyme solutions that are optimized for React 18, TypeScript, and the latest hook patterns, you can be sure these methods work with the most recent version of React, not the old, deprecated versions that some Enzyme tutorials still reference.<\/p>\n<p>Wait, one more thing: if you\u2019re just getting started with Enzyme, don\u2019t overcomplicate it. You don\u2019t need to use every single method in this guide to test if a component receives a prop. For basic cases, stick with shallow + .prop() for top-level props, and shallow + .find(ChildComponent).prop() for props passed to children. For integration tests that span multiple components, use mount + the same pattern. The rest of the methods are for edge cases, like static props or TypeScript type checks.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.sentianherb.com\/uploads\/42606\/small\/hawthorn-extract15094.png\"><\/p>\n<p>If you\u2019re running into issues with prop tests in your own code, or if you\u2019re looking for Enzyme tools that work seamlessly with your existing test setup, our team is here to help. We build solutions that cut down on test flakiness, make prop testing easier, and integrate with whatever stack you\u2019re using. Don\u2019t leave your prop logic to chance\u2014test it properly with the right tools. To discuss your Enzyme needs and find the solution that fits your workflow, reach out to our team to connect and go over your requirements.<\/p>\n<p><a href=\"https:\/\/www.sentianherb.com\/health-care-raw-material\/health-supplement-materials\/men-s-health-care-raw-material\/\">Men&#8217;s Health Care Raw Material<\/a> References:<\/p>\n<ol>\n<li>Enzyme Official Documentation &#8211; Testing Props<\/li>\n<li>React Testing Library vs Enzyme: A Developer\u2019s Guide<\/li>\n<li>TypeScript and Enzyme: Prop Type Best Practices<\/li>\n<li>React 18 Component Prop Testing with Enzyme<\/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>Hey folks, let\u2019s cut to the chase\u2014if you\u2019ve spent any time building React components, you\u2019ve run &hellip; <a title=\"How to test if a component receives a prop with Enzyme?\" class=\"hm-read-more\" href=\"http:\/\/www.algodehumor.com\/blog\/2026\/11\/19\/how-to-test-if-a-component-receives-a-prop-with-enzyme-4302-343e23\/\"><span class=\"screen-reader-text\">How to test if a component receives a prop with Enzyme?<\/span>Read more<\/a><\/p>\n","protected":false},"author":67,"featured_media":734,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[697],"class_list":["post-734","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-industry","tag-enzyme-4d74-346ca1"],"_links":{"self":[{"href":"http:\/\/www.algodehumor.com\/blog\/wp-json\/wp\/v2\/posts\/734","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.algodehumor.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.algodehumor.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.algodehumor.com\/blog\/wp-json\/wp\/v2\/users\/67"}],"replies":[{"embeddable":true,"href":"http:\/\/www.algodehumor.com\/blog\/wp-json\/wp\/v2\/comments?post=734"}],"version-history":[{"count":0,"href":"http:\/\/www.algodehumor.com\/blog\/wp-json\/wp\/v2\/posts\/734\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.algodehumor.com\/blog\/wp-json\/wp\/v2\/posts\/734"}],"wp:attachment":[{"href":"http:\/\/www.algodehumor.com\/blog\/wp-json\/wp\/v2\/media?parent=734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.algodehumor.com\/blog\/wp-json\/wp\/v2\/categories?post=734"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.algodehumor.com\/blog\/wp-json\/wp\/v2\/tags?post=734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}