<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Calum Flanagan</title>
    <description>The latest articles on Forem by Calum Flanagan (@calflan).</description>
    <link>https://forem.com/calflan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F140562%2F62b0369d-88d5-441d-b3c2-1d8a9ad5328f.png</url>
      <title>Forem: Calum Flanagan</title>
      <link>https://forem.com/calflan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/calflan"/>
    <language>en</language>
    <item>
      <title>Reduce friction and improve productivity by implementing a Design Language System</title>
      <dc:creator>Calum Flanagan</dc:creator>
      <pubDate>Wed, 06 Mar 2019 17:13:09 +0000</pubDate>
      <link>https://forem.com/calflan/reduce-friction-and-improve-productivity-by-implementing-a-design-languagesystem-3ded</link>
      <guid>https://forem.com/calflan/reduce-friction-and-improve-productivity-by-implementing-a-design-languagesystem-3ded</guid>
      <description>&lt;p&gt;I wanted to write about an &lt;a href="https://airbnb.design/building-a-visual-language/"&gt;article&lt;/a&gt; that I read by Design at Airbnb. It talks about some really important practices and discusses how they moved over to a Design Language System (DLS) - not too dissimilar to our own Style Guide that we used when I was at Zuto. They talk about how it helped them to quickly prototype, speed up their design process and release products much faster. I recommend reading the article before reading this post, just for some context (and because it's a great article).&lt;/p&gt;

&lt;p&gt;I wanted to outline some things from the article that will hopefully help those who might not understand why a tech company have such a thing a as a style guide or DLS. I also want to help you understand how we used ours at Zuto, what the value of it is for us as developers and how it can help us to prototype more.&lt;/p&gt;

&lt;p&gt;One quote from the article stood out for me:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"The DLS provides us with a shared understanding of our visual style, and streamlines contributions to a single system. This system also enables all of us to prototype and experiment with ideas in high fidelity faster and at a lower cost."&lt;br&gt;
-Airbnb&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;While we had a Style Guide in place at Zuto and we used the components that it is made up of to produce many of our products; we were still actively trying to improve on the "shared understanding of our visual style" - side of things. The design team were hard at work on figuring out the best way to display and visualise what Zuto is as a brand and discovering the best way to use that brand across the DLS, is what helps us to gain a "shared understanding of our visual style".&lt;/p&gt;

&lt;p&gt;Once we have created a DLS with a so called "visual style", prototyping becomes much easier too, because we no longer have to worry about fonts and colours (the finer details), we can focus more on the functionality of products that we want to build/prototype.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"It enables product reviews to focus on the actual concepts and experiences of a design, rather than padding, colors and type choices."&lt;br&gt;
-Airbnb&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As I said above, if we already have a DLS in place, prototyping is easy and quick. Using a style guide, we can knock up really quick and simple high fidelity wireframes, using only elements from our Style Guide. We can then use those prototypes to present our ideas to product owners or our peers. Moving on from there, we can start to mock up a more established React prototype and continue designing the prototype in the browser with the help of designers. Then when it comes to actually implementing your prototype, you will have already done a lot of the groundwork, allowing you to focus on the logic.&lt;/p&gt;

&lt;p&gt;If you really get this process down, your life as a developer would be much easier. The design team would carry a lot less weight on their shoulders too, because they would no longer have to create fully fledged designs that take a long time to conceive. Also, product owners would benefit from the fact we would be building much more MVPs, rather than all singing all dancing pixel perfect products, because we are releasing value quicker!&lt;/p&gt;

&lt;p&gt;I believe that prototyping enables us to design and build better products, and enables us to do both of those things faster and more often. It can help to move your team away from trying to build completely perfect products first time around and instead work on the MVP, test its value and iterate. If we are using elements from our style guide, then there should be no need to make small pixel perfect adjustments.&lt;br&gt;
When talking about the effect the DLS had on their process, Airbnb wrote:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Development is generally faster, since product engineers can focus more on writing the feature logic rather than the view code. Additionally, engineers and designers now share a common language.&lt;br&gt;
-Airbnb&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So development was quicker, but not only that, design and engineers are on the same page, which massively boosts productivity and reduces push backs! We certainly felt that after implementing the DLS into our workflow and involving designers in the contribution process to the DLS.&lt;/p&gt;

&lt;p&gt;However, all of the above is dependent on your tech department as a whole being committed to maintaining a style guide/DLS and following it's guidelines. Creating and more importantly, maintaining a DLS is the difficult bit. If you are able to get all engineers/designers/product owners, invested in the value that a DLS will bring, then hopefully the passion to maintain it and use it will come naturally.&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>webdev</category>
      <category>styleguide</category>
      <category>ux</category>
    </item>
    <item>
      <title>Playing with Jest</title>
      <dc:creator>Calum Flanagan</dc:creator>
      <pubDate>Tue, 26 Feb 2019 17:23:20 +0000</pubDate>
      <link>https://forem.com/calflan/playing-withjest-5hdn</link>
      <guid>https://forem.com/calflan/playing-withjest-5hdn</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TzUYyZEU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/jmgr4mv7gzs7s6kqxcsf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TzUYyZEU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/jmgr4mv7gzs7s6kqxcsf.png" alt="I stole this image from this great article https://medium.com/codeclan/testing-react-with-jest-and-enzyme-20505fec4675"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I recently started playing with Jest for a bit of fun and to see how it compared to the stack I usually use to test my React components - Jasmine (with Enzyme) and Karma as a test runner. I've heard a lot of good &lt;a href="http://tompennington.co.uk/posts/unit-testing-react-with-jest/"&gt;t&lt;/a&gt; &lt;a href="https://medium.com/@dwaynelavon/migrating-from-karma-to-jest-7a0d49a2ab55"&gt;h&lt;/a&gt; &lt;a href="https://www.springload.co.nz/blog/why-were-migrating-unit-tests-jest-and-why-you-should-too/"&gt;i&lt;/a&gt; &lt;a href="https://medium.com/welldone-software/an-overview-of-javascript-testing-in-2019-264e19514d0a"&gt;n&lt;/a&gt; &lt;a href="https://medium.com/@fastphrase/moving-from-karma-to-jest-with-a-react-based-ui-7094112e5696"&gt;g&lt;/a&gt; &lt;a href="https://dev.to/lirantal/reasons-to-love-jest-the-developer-experience-4o6f"&gt;s&lt;/a&gt; about Jest and how it basically does all the things that Jasmine does (since it was based on it)… and more now that Facebook have modified it and built on it to expand on what Jasmine does.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick and easy
&lt;/h2&gt;

&lt;p&gt;The first and one of the most useful advantages of Jest that I noticed when building an app from scratch, was how quickly I was able to set it up and get on with writing tests. Previously I had to setup Jasmine and then Karma, along with Karma's config file that you have to mess with. With Jest it was much quicker and much easier. Simply npm i jest then add the jest command to your package.json in the npm test script like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
  "test": "jest --coverage"
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;and you're done. Running tests is ridiculously fast too, because you're no longer having to spin up a Node.js process that invokes Karma.&lt;/p&gt;

&lt;p&gt;You may have noticed the addition of &lt;code&gt;--coverage&lt;/code&gt; paired with the &lt;code&gt;jest&lt;/code&gt; command in my &lt;code&gt;package.json&lt;/code&gt;. This allows you to have complete code coverage, so when you run your tests you should get an output that looks something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VRJOUE2---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/awhw40xb5v5d8bdgtwv7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VRJOUE2---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/awhw40xb5v5d8bdgtwv7.png" alt="coverage output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, you can see at the very bottom that Jest ran a test suite which failed for one reason or another, but above that might be an indicator as to why certain test have failed. In the table above, it details how much of my code has and hasn't been tested. So it's possible that some of that untested code is making my tests fail. It also saves this data as a file you can open in the browser, where you can see exactly which lines of code you've not tested in any of your components. Fantastic! All that value and all you have to do is append --coverage to the jest command.&lt;br&gt;
NOTE: you can also do this with Karma, but I thought it was worth mentioning anyway, while we're already talking about tests!&lt;/p&gt;
&lt;h2&gt;
  
  
  Familiarity
&lt;/h2&gt;

&lt;p&gt;The second cool thing about it, especially if you're transitioning from Jasmine (with Enzyme) like me, is that you can still write tests in the exact same way as Jasmine and use all of the same utilities with it (from what I've seen so far). This means that your beloved Enzyme "mount" and "shallow" can still be called upon…&lt;/p&gt;
&lt;h3&gt;
  
  
  Enzyme is still your friend
&lt;/h3&gt;

&lt;p&gt;With Jest, you are still able to use AirBnB's popular React testing utility - Enzyme. Enzyme does lots of cool things, but one cool thing I want to mention is it's ability to allow you to shallow render components in your tests. Shallow rendering a component basically means you are only rendering the component itself, not all of its children. This is particularly useful when it comes to Jest's best feature (in my opinion) - Snapshot testing, which I'll get to soon.&lt;br&gt;
If you're gonna use Enzyme, you might want to setup a &lt;code&gt;jestsetup.js&lt;/code&gt; file. Here's what mine looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Enzyme, { shallow, mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

Enzyme.configure({ adapter: new Adapter()});

global.shallow = shallow;
global.mount = mount;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This isn't a necessity for using enzyme, but if you want to be able to use the shallow and mount methods in your tests without having to import them every single time, then this is how you share them globally.&lt;/p&gt;

&lt;p&gt;In addition to this, in your &lt;code&gt;package.json&lt;/code&gt; you will need to tell Jest where this setup file lives, like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"jest": {
  "setupFiles": [
    "./tests/unit/jestsetup.js"
  ],
  "snapshotSerializers": [
    "enzyme-to-json/serializer"
  ]
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Snapshot tests
&lt;/h2&gt;

&lt;p&gt;Snapshot testing in Jest is what makes the switch from Jasmine worthwhile. Along with the fast setup and the fact you can do away with Karma now, writing a snapshot test in Jest is ridiculously easy and just as fast. In short, a snapshot test will basically capture the entire output of a component (hence shallow rendering is useful here), then when the test is ran it will compare what it captured to the actual output. So you are covering every area the code in your components.&lt;/p&gt;

&lt;h2&gt;
  
  
  Failing snapshots
&lt;/h2&gt;

&lt;p&gt;If a snapshot test fails due to a bug in your code, this will easily be picked up by the test. So we simply fix the issue, re-run the test and check that the snapshot test is passing again. However, you might be thinking what happens if changes are made to the code in a component? Won't the snapshot be out of date? Yes, but Jest has a solution. Sometimes a snapshot test can fail due to an intentional change in your code, because the snapshot for the updated component no longer matches the original snapshot for the test. To resolve this, you simply need to run this command jest --updateSnapshot and the snapshot will be updated.&lt;br&gt;
Of course, this is where you have to be careful not to record a snapshot for a component that still has buggy behaviour. So only update your snapshot when you are happy that there are no more bugs in your code i.e. your unit tests are passing.&lt;/p&gt;
&lt;h2&gt;
  
  
  Multiple snapshot tests
&lt;/h2&gt;

&lt;p&gt;When playing with Jest I created an app that allows the user to enter a search term into a search box, which in turn hits an API endpoint and returns with some results. I then pass these results through to another component using props and display them there (a search-results component). Therefore, my component would have a couple of different states based on whether or not it is populated with data from the API or not. So in conjunction with this, Jest allows me to have multiple snapshot tests to cater for the different states of the component. An example might be as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;it('matches snapshot', () =&amp;gt; {
  //Assertions here
});

//Then another test for when the component has props &amp;gt;&amp;gt;&amp;gt;&amp;gt;

it('matches snapshot after receiving props', () =&amp;gt; {
  //Assertions here
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  What I plan to look at next
&lt;/h2&gt;

&lt;p&gt;I haven't yet looked far enough into how mocking works in Jest, but if my assumptions are right, I should still be able to mock using a Jasmine spy - since Jest allows you to use other Jasmine conventions.&lt;/p&gt;

</description>
      <category>jest</category>
      <category>react</category>
      <category>javascript</category>
      <category>jasmine</category>
    </item>
  </channel>
</rss>
