<?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 James Hollingworth on Medium]]></title>
        <description><![CDATA[Stories by James Hollingworth on Medium]]></description>
        <link>https://medium.com/@jhollingworth?source=rss-da004593c887------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*B8wuREeQ87jFDiKS.jpeg</url>
            <title>Stories by James Hollingworth on Medium</title>
            <link>https://medium.com/@jhollingworth?source=rss-da004593c887------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 02:14:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jhollingworth/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[Easily testing React components with react-test-tree]]></title>
            <link>https://medium.com/qubit-engineering/easily-testing-react-components-with-react-test-tree-f9e1668b1c2d?source=rss-da004593c887------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9e1668b1c2d</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[James Hollingworth]]></dc:creator>
            <pubDate>Wed, 20 May 2015 14:59:30 GMT</pubDate>
            <atom:updated>2015-05-20T14:59:30.476Z</atom:updated>
            <content:encoded><![CDATA[<p>While I love React, testing React components leaves a lot to be desired. The <a href="https://facebook.github.io/react/docs/test-utils.html">TestUtils</a> are useful but don’t have a particularly intuitive API and lead to verbose tests, e.g.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d2ee24a172d74bebcb2eaa8992a83e79/href">https://medium.com/media/d2ee24a172d74bebcb2eaa8992a83e79/href</a></iframe><p>We’ve been working on a library at <a href="http://qubit.com/">Qubit</a> (<a href="https://qubit.workable.com/jobs/6746?utm_source=jhollingworth&amp;utm_campaign=jhollingworth_blog">We’re hiring</a>) called <a href="https://github.com/QubitProducts/react-test-tree"><strong>react-test-tree</strong></a> which removes a lot of the pain with testing React components.</p><p>It does this by creating an object that represents the given component with an API designed for testing. If you want to make assertions on an element in your component, all you need to is add a <a href="https://facebook.github.io/react/docs/more-about-refs.html#the-ref-string-attribute">ref</a> and it will be exposed for testing. Rather than having to simulate events, we give you simple functions (e.g. .click()) to call instead.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e306b2e1c88eccae437f7b5aad23a5b/href">https://medium.com/media/0e306b2e1c88eccae437f7b5aad23a5b/href</a></iframe><p>So what about if I’ve got a collection of elements? We introduce a new attribute, refCollection, which you must add to the parent element. Any children will be available as an array on the test tree.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd80d2182bfb2036df1ec158bad49463/href">https://medium.com/media/cd80d2182bfb2036df1ec158bad49463/href</a></iframe><p>Often when you’re writing your tests you want to prevent certain parts of the component from being rendered e.g. if that part isn’t relevant to the test. React introduced <a href="https://facebook.github.io/react/docs/test-utils.html#shallow-rendering">shallow rendering</a> in v0.13 however we’ve found its rather limited, not allowing the fine grained control we desired. react-test-tree provides a different approach, allowing you to stub refs:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/55a363835986e60331bf54dc7e9ca201/href">https://medium.com/media/55a363835986e60331bf54dc7e9ca201/href</a></iframe><p>Another thing we often found ourselves doing was passing values down through the <a href="https://www.tildedave.com/2014/11/15/introduction-to-contexts-in-react-js.html">context</a> (e.g. if you want to mock <a href="https://github.com/rackt/react-router">react-router’s</a> router) . This is again trivial with react-test-tree, all you need to do is pass your context object in via the childContext option.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9b522fdc3a752385fa733ad21072652d/href">https://medium.com/media/9b522fdc3a752385fa733ad21072652d/href</a></iframe><p>We’ve found react-test-tree is a massive help in testing react components. Theres always room for improvement so would love to hear <a href="https://github.com/qubitproducts/react-test-tree/issues">what you think</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9e1668b1c2d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/qubit-engineering/easily-testing-react-components-with-react-test-tree-f9e1668b1c2d">Easily testing React components with react-test-tree</a> was originally published in <a href="https://medium.com/qubit-engineering">Qubit Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>