<?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 ReactVT on Medium]]></title>
        <description><![CDATA[Stories by ReactVT on Medium]]></description>
        <link>https://medium.com/@reactvt?source=rss-31a4cda2a374------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by ReactVT on Medium</title>
            <link>https://medium.com/@reactvt?source=rss-31a4cda2a374------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 20:27:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@reactvt/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[Data Driven React Testing]]></title>
            <link>https://medium.com/@reactvt/data-driven-react-testing-56e27c14a6a7?source=rss-31a4cda2a374------2</link>
            <guid isPermaLink="false">https://medium.com/p/56e27c14a6a7</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[ReactVT]]></dc:creator>
            <pubDate>Fri, 18 Aug 2017 00:42:39 GMT</pubDate>
            <atom:updated>2017-08-18T03:24:32.384Z</atom:updated>
            <content:encoded><![CDATA[<p>We all know how important testing can be for ensuring that an app remains stable as it is updated, but let’s be honest, the process of writing tests can feel tedious and leaves plenty of opportunities for human error to create invalid tests. As an app grows in size, it can be more difficult to reason about exact information you need to test a specific item, such as its ID, without digging through files of code just to find that one key piece of data. Furthermore, if you want to test a specific DOM element that doesn’t have an ID, the process of finding a way to select that node becomes even more painful as you now have to reason about how that one element fits into the overall structure of your webpage in order to run any tests against it.</p><p>The ReactVT team felt like this process could be improved upon, so we set out to make a React testing library where test creation is driven by data that is extracted from that application that is being tested. That way, users are presented with all of the data that they can test with, eliminating the need to dig through code to find that information while allowing tests to be confined to only relevant data sources.</p><p>On a high level, our application is split into separate components. An npm package that is imported into the parent component of the user app, and a chrome extension which forms a connection with the user app. The chrome extension then allows for users to make assertions which can be tested in real time as the user interacts with their app.</p><p>Building out a React testing library required us to get information like state and props from the user’s application. There were a couple of considerations when we approached this:</p><ol><li>Wrap around the entirety of the user’s application and parse the code completely. This would have been a tedious task of creating a giant parser.</li><li>Explore the possibility of getting information from the user application’s React instance. We ultimately ended up taking this route since it’s much less intrusive and allowed us to keep the installation light and set up simple.</li></ol><p>What did we find when we console logged the React instance?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*RrBtVW3je1hPe3PDW80laA.png" /><figcaption>A deeply nested virtual DOM object , complete with circular references</figcaption></figure><p>We were ecstatic when we found that we were able to extract all the state, props, and other virtual DOM information, complete from the top-level component — down to the most basic presentational components. This discovery would lay the foundation of our entire testing library. We now have all the relevant DOM information to be tested.</p><p>In order to get all that information, we recursively traverse through the virtual DOM whenever it changes state, where we collect all relevant information that is needed for our chrome extension to render the user app’s component tree and provide the necessary information regarding the contents of application such as Ids, Classes, etc. At that point, the user can interact with React VT’s D3 tree graph in order to specify specific actions and tests that they want to create in order to write a test suite, which will then be sent back to the user’s application where they are updated in real time as the user’s app state changes.</p><p>Why would we attempt to even integrate D3 in React? D3 is a phenomenal library. It is currently one of the most popular library for data visualizations and rightfully so as it contains many statistical functions and outstanding support for data manipulation. However, D3 has notable downsides which were convincing enough to make that transition into attempting to integrate D3 in React. For those that use D3 or are familiar with its syntax, the syntax can seem very unintuitive and verbose. Here is an example comparing the amount of code needed to generate a single rectangle in D3 compared to the same rectangle in React:</p><p>D3 representation of a rectangle</p><p>d3. select(“svg”)<br> .attr(“width”, 500)<br> .attr(“height”, 400)<br> .append(“rect”)<br> .attr(“width”, 100)<br> .attr(“height”, 300)<br> .attr(“x”, 30)<br> .attr(“y”, 10)</p><p>React representation of the same rectangle</p><pre>&lt;svg width=”500&quot; height=”400&quot;&gt;<br> &lt;rect width=”100&quot; height=”300&quot; x=”50&quot; y=”20&quot; /&gt;<br>&lt;/svg&gt;</pre><p>In addition, the graphs produced by D3 are tailored with a high degree of specificity which creates lack of flexibility in terms of reusability. There are ways to go around this issue, but it requires a lot of additional effort whereas in React, various chart components could be generated to build off of the same data. The most significant reason that influenced our decision to incorporate D3 in React is the fact that D3 performs wonderfully when updates are simple, but when there are lot of elements to keep track of, things become too overwhelming. This issue stems from D3’s enter, update, exit lifecycle which has serious problems with state management as manual calculations needs to be done for every instance of change. With React’s performant diffing algorithm and virtual DOM, we can alleviate the issue and simply let React deal with the state changes.</p><p>Although there are various ways in combining the two libraries, the approach that seemed most intuitive to us revolved around letting the two libraries do what they do best. D3’s strong suit is its ability to do intensive data computations whereas React shines in everything that involves DOM rendering. To combine the two together, we leveraged D3 to generate all the drawing instructions like coordinates and used React to construct the actual DOM elements by passing the D3 generated information down to components through props.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56e27c14a6a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>