<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Hugh Hartigan on Medium]]></title>
        <description><![CDATA[Stories by Hugh Hartigan on Medium]]></description>
        <link>https://medium.com/@hartigan.hm?source=rss-3440e697c4b4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YRjt2oY0_svvNg2nMXbB-A.jpeg</url>
            <title>Stories by Hugh Hartigan on Medium</title>
            <link>https://medium.com/@hartigan.hm?source=rss-3440e697c4b4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 12:56:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hartigan.hm/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Finding Solid Ground in the Open Source Jungle]]></title>
            <link>https://medium.com/@hartigan.hm/finding-solid-ground-in-the-open-source-jungle-dc7a220c6a25?source=rss-3440e697c4b4------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc7a220c6a25</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[enzyme]]></category>
            <category><![CDATA[turing]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Hugh Hartigan]]></dc:creator>
            <pubDate>Fri, 09 Feb 2018 03:51:24 GMT</pubDate>
            <atom:updated>2018-02-09T03:51:24.270Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QBv6xKM2jFfkmRG-r-GHxQ.jpeg" /></figure><p>Having only truly hopped onto the software development train a few months ago, I’m still all too familiar with how daunting a wall of code can be. You find yourself staring at a screen full of numbers and letters, trying to decipher something, anything:</p><blockquote>Which line is Judo?</blockquote><blockquote>Where is the file that teaches me how to fly an Apache helicopter nested?</blockquote><blockquote>How many cat GIFs can I push to GitHub before Agent Smith crashes through the ceiling?</blockquote><p>Not enough. Not nearly enough.</p><p>Having grappled with JavaScript for the past six months at break-neck speed, I can confidently say that I feel pretty comfortable with the language now. Even if something seems strange and unusual, after a little bit of tinkering, I can figure out what’s going on. With this swagger, I decided it was time to contribute to an open source project. My team and I picked a code base built using React, read all of the docs, sifted through the issues, and bookmarked a few that seemed doable.</p><p>Then install happened…</p><p>I found myself under a dark canopy of Ruby files and Gems. I followed all of the instructions beating back errors with my machete and, finally, found myself staring three terminal windows in the face: one running redis-server, one running guard, and one running gulp.</p><blockquote>*gulp*</blockquote><p>But regardless of my worry, the project was running and all I had to do was find a comfortable spot to camp. We revisited some of the issues we had tagged and, unfortunately, most of the simpler ones involving React components had been closed. The lone issue left had to do with rounding out the testing suite for all React components. At Turing School of Software &amp; Design, we are fed the concept of Test Driven Development (TDD) early and often, so that issue was absolutely within our reach.</p><p>Since there were about six components that needed a full testing suite, we decided to start small, picking one specific JSX (JavaScript XML) file for a particular component. To familiarize ourselves with how the tests were supposed to be written, we had a few crucial questions that needed to be answered:</p><blockquote>Where was our component being rendered and what data was necessary for successful rendering?</blockquote><blockquote>What was its parent component?</blockquote><blockquote>Was there a testing suite similar to the one we needed?</blockquote><p>Once all of these questions were answered, we were able to start. Our component only needed two pieces of data to render, a mock object and a boolean value (we gleaned this from its parent component). A testing suite for the parent component had already been completed as well, which showed us the structure for the mock data we needed for rendering, as well as how each test should be structured.</p><p>This last piece was important for a few reasons:</p><ul><li>Coding semantics and structure are important when working with a team. This ensures consistent coding style and readability.</li><li>At Turing we learn how to test in a number of ways, but use a particular format for React. This OS project used a different method than we were used to, so we had to familiarize ourselves with their best practices in order to effectively contribute in a meaningful way.</li></ul><p>With these tools at our disposal, my team and I were able to successfully write nine tests, covering any and all aspects of conditional rendering for our component. We made sure to follow the contributor guidelines before we submitted a pull request for our branch, ensuring that all of our changes and commits were to code. Once everything looked clear, we submitted out first ever PR to an open source project!</p><p>Now, what’s exciting about this experience is what happened next. By the end of the day, we were invited to a Slack channel for the open source project that had a wealth of active users. The moderator for the project contacted us the following day, asking if we could adjust our tests to use a new convention they were trying to migrate to. What was that convention you ask? The very same format of test building that we are taught at Turing!</p><p>Without going into too much technical detail as to the differences, the original tests were built using ReactTestUtils and the moderator wanted to convert the tests to use Enzyme which is “a JavaScript Testing utility for React that makes it easier to assert, manipulate, and traverse your React Components’ output.” Below are a few examples of the refactored code we completed, with the older tests first, followed by the newer ones.</p><p>This test checked for the proper rendering of the React component:</p><pre>// Using ReactTestUtils</pre><pre>it(&#39;Should exist&#39;, () <em>=&gt;</em> {<br>  <em>const</em> renderedUpload = ReactTestUtils.renderIntoDocument(<br>    &lt;div&gt;<br>      &lt;Upload upload={mockUpload} linkUsername={true} /&gt;<br>    &lt;/div&gt;<br>);</pre><pre>  expect(renderedUpload).to.exist;<br>});</pre><pre>// Using Enzyme</pre><pre>it(&#39;Should exist&#39;, () <em>=&gt;</em> {<br>  <em>const</em> renderedUpload = shallow(<br>    &lt;Upload upload={mockUpload} linkUsername={true} /&gt;<br>  );</pre><pre>  expect(renderedUpload).to.exist;<br>});</pre><p>Already you can see that the test uses two less lines of code, only requiring the React component itself, as opposed to having to be wrapped in a &lt;div&gt; element.</p><p>This test checks conditional rendering of an image filename longer than sixty characters:</p><pre>// Using ReactTestUtils</pre><pre>it(&#39;Should not have an ellipsis if file_name is less than 60 characters&#39;, () <em>=&gt;</em> {<br>  <em>const</em> renderedUpload = ReactTestUtils.renderIntoDocument(<br>    &lt;div&gt;<br>      &lt;Upload upload={mockUpload} linkUsername={true} /&gt;<br>    &lt;/div&gt;<br>  );</pre><pre><em>  const</em> fileElement = renderedUpload.querySelectorAll(&#39;.desktop-only-tc&#39;)[0].children[0].innerHTML;</pre><pre>  expect(fileElement).to.not.include(&#39;…&#39;);<br>});</pre><pre>// Using Enzyme</pre><pre>it(&#39;Should not have an ellipsis if file_name is less than 60 characters&#39;, () <em>=&gt;</em> {<br>  <em>const</em> renderedUpload = shallow(<br>    &lt;Upload upload={mockUpload} linkUsername={true} /&gt;<br>  );</pre><pre>  <em>const</em> fileElement = renderedUpload.find(&#39;.desktop-only-tc&#39;).first().children().text();</pre><pre>  expect(fileElement).to.not.include(&#39;…&#39;);<br>});</pre><p>Here, the chained methods become more explicit and less abstract. Whereas in the first snippet querySelectorAll is used, Enzyme makes use of more explicit language in .find(), which locates all elements with a passed class or id. Additional improvements come from using .first() over an index of 0 and .text() over .innerHTML.</p><p>This test checks the conditional rendering of an uploader on the DOM based on whether the prop linkUsername is true or false:</p><pre>// Using ReactTestUtils</pre><pre>it(&#39;Should render uploader differently if linkUsername is true&#39;, () <em>=&gt;</em> {<br>  <em>const</em> renderedUpload = ReactTestUtils.renderIntoDocument(<br>    &lt;div&gt;<br>      &lt;Upload upload={mockUpload} linkUsername={true} /&gt;<br>    &lt;/div&gt;<br>  );</pre><pre>  <em>const</em> uploader = renderedUpload.querySelectorAll(&#39;.desktop-only-tc&#39;)[1].innerHTML;</pre><pre><em>  const</em> expected = &#39;&lt;a href=&quot;/users/Ragesoss&quot;&gt;Ragesoss&lt;/a&gt;&#39;;</pre><pre>  expect(uploader).to.equal(expected);<br>});</pre><pre>// Using Enzyme</pre><pre>it(&#39;Should render uploader differently if linkUsername is true&#39;, () <em>=&gt;</em> {<br>  <em>const</em> renderedUpload = shallow(<br>    &lt;Upload upload={mockUpload} linkUsername={true} /&gt;<br>  );</pre><pre><em>  const</em> uploader = renderedUpload.find(&#39;.desktop-only-tc&#39;).at(1).html();</pre><pre><em>  const</em> expected =&#39;&lt;td class=&quot;desktop-only-tc&quot;&gt;&lt;a href=&quot;/users/Ragesoss&quot;&gt;Ragesoss&lt;/a&gt;&lt;/td&gt;&#39;;</pre><pre>expect(uploader).to.equal(expected);<br>});</pre><p>This final refactor goes a step further to show how easy Enzyme is to read. Instead of having to isolate a specific index, we simply use .at(1) to select the second element in the array. Additionally, .html is used over .innerHTML, which is more clear and to the point.</p><p>While this comparison isn’t to say that Enzyme is better than ReactTestUtils, it shows the importance of readability in your code. Writing tests can seem like a pain: writing code to test your code doubling the volume of your code. However, in the long run, testing saves us headaches and, should something break, helps us isolate where an error might be. The root concern here can be summed up in two words: Developer Empathy. One day, should you decide to start an open source project, you want your code to be as accessible and easy to understand as possible. For those generous developers volunteering their skills, this cuts down on ramp up time and encourages them to come back and contribute to a well maintained, clear, and concise code base.</p><p>Though the open source jungle can seem daunting and foreboding, taking that first step is often the hardest. There may be tangles and brambles to fight through, wild beasts to confront, and darkness to overcome, but once you make it through the thickets, you can find a comfortable spot to call your own. You start seeing the beauty of the environment you’re in and recognize familiarities that you may not have seen before. Eventually, you may even be able to make that jungle a better place and, though you may not have mastered the jungle entirely, you’re more experienced for trying at all.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g4hK5L4qAgEg-zWfDg-KXQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc7a220c6a25" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>