<?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 Julia Mitchelmore on Medium]]></title>
        <description><![CDATA[Stories by Julia Mitchelmore on Medium]]></description>
        <link>https://medium.com/@julia.mitchelmore?source=rss-c17dcd55928c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4xeIQqTuRYnNnnV_nTbJ2Q.jpeg</url>
            <title>Stories by Julia Mitchelmore on Medium</title>
            <link>https://medium.com/@julia.mitchelmore?source=rss-c17dcd55928c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 08:12:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@julia.mitchelmore/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[So you want get better at CSS]]></title>
            <link>https://medium.com/tech-eatwith/so-you-want-get-better-at-css-9c63e63d7d1a?source=rss-c17dcd55928c------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c63e63d7d1a</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Julia Mitchelmore]]></dc:creator>
            <pubDate>Tue, 22 Oct 2019 15:32:56 GMT</pubDate>
            <atom:updated>2019-10-22T15:32:56.073Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_2umLvDCyvmVcHKze1wlxQ.jpeg" /></figure><h3>So you want get better at CSS…</h3><p>React, Angular, Vue, Next.js, mobX, TypeScript — front-end development in 2019 is full of buzz-words. But what about good old CSS? For some reason it gets forgotten, swept under the carpet as a ‘lesser’ skill. Poor, neglected old friend 😞 It’s a shame because in reality, CSS is an incredibly powerful tool that turns plain into exciting and ‘nice’ into WOW!</p><p>It’s time for the CSS revolution, and I’m glad you’re on board. Come and discover some of the awesome features of CSS and brush up on the standards you might-just-have become fuzzy about. Listed below is a series of resources you can use to get your styles up to scratch. Let’s begin.</p><h3>Level One: The basics</h3><p>aka the things you’ll come across every day that you write CSS and if you don’t understand them then you really should get cracking now. Like, right now. (Please don’t tell me your site is laid out using tables…)</p><h4>The box model</h4><p>Pretty much everything in CSS starts as a box, so we need to understand how these boxes interact. We’re talking padding and margins here, the basic display property and how to use all this properly. In which cases does margin collapse? Can you explain why the following selector is included in CSS-resets, what it does and what the other values are?</p><pre>* {<br>  box-style: border-box;<br>}</pre><p><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model">Introduction to the CSS basic box model</a><br><a href="https://internetingishard.com/html-and-css/css-box-model/">CSS Box Model</a><br><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Mastering_margin_collapsing">Mastering margin collapsing</a><br><a href="https://tympanus.net/codrops/css_reference/box-sizing/">Codrops: Box-sizing</a></p><h4>Positioning</h4><p>No, not everything must be position: absolute. Yes, you can use position: fixed without breaking everything. No, you don’t need to add position: relative willy-nilly — but you do need it to get other CSS features to work correctly. And what about this position: sticky? Study your positions thoroughly.</p><p><a href="https://css-tricks.com/almanac/properties/p/position/">CSS Tricks: position</a><a href="http://www.barelyfitz.com/screencast/html-training/css/positioning/"><br>Learn CSS Positioning in Ten Steps</a><br><a href="https://css-tricks.com/absolute-relative-fixed-positioining-how-do-they-differ/">Absolute, Relative, Fixed Positioning: How Do They Differ?</a><br><a href="https://www.freecodecamp.org/news/how-to-use-the-position-property-in-css-to-align-elements-d8f49c403a26/">How to use the position property in CSS to align elements</a></p><h4>:before &amp; :after</h4><p>You know pseudo-classes like :hover and :checked. But if you really want to feel confident in your CSS though, mastering the psuedo-<em>elements</em> :before and :after is key. These two friends will open up a whole world of possibilities for you.</p><p><a href="https://www.smashingmagazine.com/2011/07/learning-to-use-the-before-and-after-pseudo-elements-in-css/">Learning To Use The :after and :before Pseudo Elements in CSS</a><br><a href="https://krasimirtsonev.com/blog/article/CSS-before-and-after-pseudo-elements-in-practice">CSS: :before and :after pseudo elements in practice</a><br><a href="https://wpshout.com/three-practical-uses-css-pseudoselectors/">Three Practical Uses of the :before and :after CSS Pseudoselectors</a></p><h4>z-index &amp; the Stacking Context</h4><p>That nearly sounds like a hipster band doesn’t it? I’d go see them in concert! Sadly though, rather than providing rocking tunes, stacking context usually just creates a whole lot of headaches and frustrations. Adding z-index: 99999999; is never the solution — instead, properly learn how to stack your elements.</p><p><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context">MDN: The Stacking Context</a><br><a href="https://www.oreilly.com/library/view/developing-web-components/9781491905685/ch04.html">Understanding and Managing z-index</a><br><a href="https://tiffanybbrown.com/2015/09/css-stacking-contexts-wtf/index.html">CSS stacking contexts: What they are and how they work</a><br><a href="https://philipwalton.com/articles/what-no-one-told-you-about-z-index/">What No One Told You About Z-Index</a></p><h4>Flexbox and grid layouts</h4><p>Having now fully understood the box-model and positioning, our final basic skill is to conquer layouts using the great tools provided to us by CSS3: display: flex and display: grid . Once you know how they work you’ll find yourself sprinkling their magic everywhere you turn (don’t overdo it!), because it just all <em>makes dollars makes sense.</em></p><p><a href="https://flexboxfroggy.com/">Flexbox Froggy</a><br><a href="https://css-tricks.com/snippets/css/a-guide-to-flexbox/">A Complete Guide to Flexbox</a><br><a href="http://cssgridgarden.com/">Grid Garden</a><br><a href="https://css-tricks.com/snippets/css/complete-guide-grid/">A Complete Guide to Grid</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LKQMnR2tyaQqUvLe8hQl9g.jpeg" /></figure><h3>Level Two: Getting fancy</h3><p>Cool cool cool, you’re confident around a layout. Good stuff good stuff good stuff. But now you’re itching to make it look <em>interesting</em>, to add some sparkle to your page. ✨ Maybe even… make something move?</p><h4>Gradients</h4><p>Sometimes overlooked, gradients can elevate a design. And while yes, you could just rely on a generator to write the CSS for you, to become a master you need to learn how to call the functions correctly — and where they can all be applied. Layering works too!</p><p><a href="https://css-playground.com/view/45/css-gradient-playground">CSS Gradient Playground</a><br><a href="https://cssgradient.io/">CSS Gradient Generator</a><br><a href="https://webdesign.tutsplus.com/tutorials/how-to-use-gradients-on-the-web--cms-29922">How to Use CSS Gradients on the Web</a></p><h4>Transforms</h4><p>With translate, rotate, scale and skew, CSS transforms let us take a simple box and start to play with shape and dimension (but be reminded of what we learned about the stacking context above!). With transforms, you can turn a square into a diamond, a rhombus, a bigger square, a smaller square… and even work in 3d space.</p><p><a href="https://html-css-js.com/css/generator/transform/">Transform CSS Generator: Scale, Rotate, Translate and Skew</a><br><a href="https://marksheet.io/css-transform.html">Fashioning unique shapes</a><br><a href="https://blog.logrocket.com/the-noobs-guide-to-3d-transforms-with-css-7370aafd9edf/">The noobs guide to 3D transforms with CSS</a><br><a href="https://3dtransforms.desandro.com/">Intro to CSS 3D Transforms</a></p><h4>Transitions</h4><p>The little sister to animations (below), the transition property lets you, well, transition between two states. Use to smoothly change opacity or color or whatever you want — except display because that would just be <em>too</em> easy.</p><p><a href="https://cssreference.io/transitions/">Transitions in CSS</a><br><a href="https://www.sitepoint.com/css3-transition-properties/">CSS3 Transition Property Basics</a><br><a href="https://stackoverflow.com/questions/3331353/transitions-on-the-display-property">StackOverflow: Transitions on the display: property</a><br><a href="https://www.webdesignerdepot.com/2014/05/8-simple-css3-transitions-that-will-wow-your-users/">8 simple CSS3 transitions that will wow your users</a></p><h4>Easing functions</h4><p>When making our smooth transitions, we can specify the rate of change via easing. CSS gives us some basic options like ease or the slightly-more-complex ease-in-out, but that doesn’t always feel authentic. For more granular control, cubic-bezier() is where it’s at.</p><p><a href="https://css-tricks.com/ease-out-in-ease-in-out/">CSS Tricks: ease-out, in; ease-in, out</a><br><a href="https://easings.net/">Easing functions visualised</a><a href="https://cubic-bezier.com/"><br>Cubic Bezier generator</a></p><h4>Animations</h4><p>Jiggles, shakes, slides — not just reserved for the dancefloor; the powerful @keyframes opens up a world of animation possibilities. Most CSS properties can be animated, and provide a little pop of delight on the page ( — and I mean <em>little</em>, don’t get too excited and revert to the horror of the flashing 90s…).</p><p><a href="https://thoughtbot.com/blog/css-animation-for-beginners">CSS Animation for Beginners</a><br><a href="https://cssanimation.rocks/">CSS Animation Tutorials</a><br><a href="https://codepen.io/kylewetton/pens/">Kyle Welton on CodePen</a> (has some great pure-CSS animation examples)<br><a href="https://www.creativebloq.com/inspiration/css-animation-examples">19 cool CSS animation examples to recreate</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s-sMR49RfFJ0KIbFsZ98fA.jpeg" /></figure><h3>Level Three: Adding structure</h3><p>OK so by this stage you’re thinking that you’re pretty handy around CSS. Likely, you also are already working as a developer and are itching to put your sick-style-skills into practise. Awesome! But not so fast — writing production CSS is a different ballgame, yet there are plenty of tools waiting to help you on your way.</p><h4>Naming conventions</h4><p>Be gone, #myClass! CSS can easily get messy, and one main culprit is badly-named classes. Just like adopting a puppy, adopting a CSS naming convention will only bring happiness into your life. They help with maintainability, DRY-ness, and just plain understanding what-the-hell is going on.</p><p><a href="https://www.freecodecamp.org/news/css-naming-conventions-that-will-save-you-hours-of-debugging-35cea737d849/">CSS Naming Conventions that Will Save You Hours of Debugging</a><br><a href="https://css-tricks.com/bem-101/">BEM 101</a><br><a href="https://blog.goyello.com/2019/07/10/smacss-methodology/">SMACSS Methodology</a><br><a href="http://bdavidxyz.com/blog/how-to-name-css-classes/">How to name CSS classes</a></p><h4>Preprocessors</h4><p>Once upon a time, someone got annoyed by having to write long lists of selectors (+ more) and invented the CSS preprocessor. Give me NESTING! Give me VARIABLES! Give me MIXINS! It still looks like CSS, but just acts a 1000% better.</p><p><a href="https://medium.com/@sedwardscode/css-preprocessors-what-why-how-7bc5a7a564de">CSS Preprocessors: What? Why? …How?</a><br><a href="https://raygun.com/blog/css-preprocessors-examples/">Popular CSS Preprocessors With Examples: Sass, Less &amp; Stylus</a><br><a href="https://www.freecodecamp.org/news/the-complete-guide-to-scss-sass-30053c266b23/">The Complete Guide to SCSS/SASS</a></p><h4>CSS-in-JS</h4><p>Eventually though, someone else got annoyed by having a separate CSS file and thought ‘I know, let’s do it all in JavaScript!’. Kinda cheating, really, and yet it’s also kinda magic. Rather than relying on naming classes (see above), you add styling to elements, and let JS do the rest.</p><p><a href="https://mxstbr.com/thoughts/css-in-js/">Max Stoiber: Why I Write CSS in JS</a><br><a href="https://blog.logrocket.com/5-things-you-can-do-in-css-in-js-that-you-didnt-know-about-c422fb67ceb6/">5 things you didn’t know you can do in CSS-in-JS</a><br><a href="https://2019.stateofcss.com/technologies/css-in-js/">The State of CSS 2019: CSS-in-JS</a><br><a href="http://Refactoring an alert component from CSS to CSS-in-JS">Refactoring an alert component from CSS to CSS-in-JS</a></p><h4>CSS variables</h4><p>In tandem with all those nice libraries being created, CSS itself is slowly evolving, dragging itself into the modern era. One noteworthy addition to the language is variables — now without a preprocessor! Oh, the times are exciting.</p><p><a href="https://www.freecodecamp.org/news/everything-you-need-to-know-about-css-variables-c74d922ea855/">Everything you need to know about CSS variables</a><br><a href="http://What is the difference between CSS variables and preprocessor variables?">What is the difference between CSS variables and preprocessor variables?</a><br><a href="https://developers.google.com/web/updates/2016/02/css-variables-why-should-you-care">CSS Variables: Why should you care?</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tZ9w1kK1RQOyTaOsnZJ2Pw.jpeg" /></figure><h3>Level Four: Showing off</h3><p>Now that you’ve got all that down pat, you deserve a gold star ⭐️ and the right to call yourself a <em>real</em> front-end developer. To finish off, here are some rapid-fire cool CSS things that you probably didn’t even realise were possible. Boom, CSS FTW 🔥</p><h4>box-shadow</h4><p>Forget drop-shadows: did you know that <a href="https://medium.com/@sashatran/3-cool-tricks-box-shadow-can-do-6e50560737f4">box-shadow can duplicate your shape</a>?! And then duplicate it again, and again, and again?</p><h4>object-fit</h4><p>object-fit brings background-size to image tags, letting you <a href="https://www.w3schools.com/css/css3_object-fit.asp">resize while maintaining aspect-ratio</a>. What more could you want?</p><h4>Animating stroke-dashoffset</h4><p>Take an SVG path, and add a little animation to <a href="https://css-tricks.com/svg-line-animation-works/">create a line-drawing.</a> It’s as though your shape was drawing itself ✏️</p><h4>clip-path</h4><p>If you want to <a href="https://alligator.io/css/clipping-with-clip-path/">create complex shapes beyond circles and squares</a>, clip-path is the answer. Think SVG shapes, but written in CSS.</p><h4>currentColor</h4><p><a href="https://www.quirksmode.org/css/color/currentcolor.html">Cascade text-color via </a><a href="https://www.quirksmode.org/css/color/currentcolor.html">currentColor</a>, which can be applied to any colour-accepting CSS property. Makes theme-switching easy-peasy.</p><h4>Bonus: Dark Mode</h4><p>Apple’s latest releases have brought Dark Mode to Mac, iOS &amp; iPad, and you can <a href="https://tombrow.com/dark-mode-website-css">target the dark mode setting via a nifty </a><a href="https://tombrow.com/dark-mode-website-css">@media query</a>. Come to the dark side 😈</p><h3>Recap: Top resources</h3><p>If you can’t tell already, I’m really passionate about CSS 😂 I find it immensely enjoyable to make a slick-looking layout, but also to experiment and see what can be created (hint: just about anything!). It frustrates me when people undervalue CSS as a skill, because it’s actually <em>really cool,</em> <em>OK?!</em></p><p>Seeing as you’ve made it this far, you’re probably convinced of the downright awesomeness of CSS — YAY! 🎉 So now it’s time to go out and create some beautiful styles of your own, with the help of these resources:</p><ul><li><a href="https://css-tricks.com/"><strong>CSS Tricks</strong></a>: The almanac of everything CSS. If you have a question, it will have the answer. Simple.</li><li><a href="http://www.csszengarden.com/"><strong>CodePip</strong></a>: Makers of Flexbox Froggy and Grid Garden as listed in the ‘basics’ section, they have a host of games which teach coding (CSS and beyond) concepts in a really fun way.</li><li><a href="http://www.csszengarden.com/"><strong>CSS Zen Garden</strong></a>: One HTML file, many different style sheets. It’s the original showcase of just what is possible with the magic of CSS.</li><li><a href="https://codepen.io/challenges/"><strong>CodePen Challenges</strong></a>: Each week, CodePen releases a Challenge topic to get your creative juices flowing. It’s a great way to put your theory into practise, and can lead to some awesome ‘pens’. (Shameless plug: <a href="https://codepen.io/juliamitchelmore">check out mine</a>!)</li></ul><p>Happy styling! 👩‍🎨</p><p><em>Julia works at </em><a href="http://eatwith.com/"><em>Eatwith</em></a><em>, which brings people together through food at tables all around the world. For more articles and insights from the tech &amp; product team, please subscribe to the </em><a href="https://medium.com/tech-eatwith"><em>Tech @ Eatwith</em></a><em> blog.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c63e63d7d1a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tech-eatwith/so-you-want-get-better-at-css-9c63e63d7d1a">So you want get better at CSS</a> was originally published in <a href="https://medium.com/tech-eatwith">Tech @ Eatwith</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Untangling the code refactor]]></title>
            <link>https://medium.com/tech-eatwith/untangling-the-code-refactor-c69df8f2e7a7?source=rss-c17dcd55928c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c69df8f2e7a7</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[code]]></category>
            <dc:creator><![CDATA[Julia Mitchelmore]]></dc:creator>
            <pubDate>Wed, 29 May 2019 15:32:35 GMT</pubDate>
            <atom:updated>2019-05-29T15:32:35.396Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iJ3Dg67n1RIcAtTB94JEdA.jpeg" /></figure><p>Earlier this morning I pushed a commit and a huge smile spread across my face. That push marked the end of a year-long refactor I have been working on to simplify and clarify the <a href="http://www.eatwith.com/">Eatwith</a> front-end codebase, and looking at the clean code just makes me happy. 🎉</p><p>Tech debt is an inevitable part of coding; there isn’t enough time in the day to have perfect code while still shipping features. Sadly though, the situation can easily get out of hand, as had happened for us. Our codebase had changed hands a few times without consensus of style and approach, resulting in code which was difficult to read and bugs which were difficult to fix. Now a year on though, it is in a much better place. Not only is the code more performant, but also more maintainable, composable and understandable.</p><p>The refactoring journey is a long (or even never-ending) one, but is ultimately worth the effort. Here’s how to approach any refactor, but especially one which involves a lot of complexity or legacy code.</p><h4>Break it into small pieces</h4><p>As with any big project, it can be tempting to dive straight in to a refactor without stopping to think about what you want to achieve first. Doing this will probably mean more work further down the line — or a lot of frustration when you realise just how much work is ahead of you.</p><p>Instead, plan how you’re going to approach your refactor: what do you want from your code when everything is done? Then break down that plan into pieces. You may decide to focus on one file at a time, one page at a time or one piece of functionality at a time; whatever you choose, make sure that it is a containable piece of work which contributes to your end goal.</p><p>When actually refactoring, break up that task as well. Staring at 38 files which need to be modified because all the functions of a file have been renamed (and can’t just be updated with find+replace) is daunting. Instead, focus on replacing just one function at a time, it will feel manageable rather than overwhelming.</p><h4>Make time or take time</h4><p>The importance of refactoring can be hard to understand by people in your company who want to add new features and drive a product forward. It’s unlikely that you’ll be handed a few glorious weeks (or months!) to work solely on improving the codebase. Instead you will need to convince stakeholders that this work is a valuable use of your resource, and fit it in around other tasks.</p><p>Where possible, create refactor tickets which live alongside feature tickets and can be planned in to sprints/upcoming work — following step one and breaking up your refactor into pieces will help you here! If a refactor task exists in the backlog alongside any other bugs or features, it’s much more likely that you’ll be able to allocate time to work on it.</p><p>A refactor can also be a great project to work on in your downtime between business-urgent tasks. You’ll come to love the satisfaction of rewriting code more than scrolling through HackerNews, trust me 😉</p><h4>Stick to your plan</h4><p>Web development in 2019 still involves a lot of ‘OOH SHINY!’ and ‘Just released: v18.203.0!’ which will threaten to derail your hard work. Jumping to include upgrades or new packages likely means having to do a refactor on top of your refactor — and that can only end one way: with a spaghetti-mess of a codebase worse than the one you started with.</p><p>Remind yourself of the purpose of your refactor: to ensure consistency, create maintainability and clarify your code. Keep this in mind when making any decisions, and don’t be afraid to say no to suggestions which would add extra complexity. This does not mean that your codebase needs to remain stagnant throughout the course of your refactor, but rather to be conscious of which new sparkly thing will benefit your product, and which will just cause more headaches and heartaches. Once this work is complete, you will be in a much better place to easily upgrade your code again in the future.</p><h4>Acknowledge when to refactor, and when to restructure</h4><p><em>Restructuring: </em>updating your code style or moving functions/etc. without changing its underlying mechanics.<br><em>Refactoring</em>: reworking code by pulling it apart and putting it together in a cleaner, better way.</p><p>Some pieces of code are inherently complicated. Perhaps that is some data which is handled oddly, highly dependent functions, or nested functionality which is hard to trace and likely to break. Properly refactoring these sections of your codebase would take more time than is feasible to spend on it.</p><p>For these files or functions, you may need to accept that a restructure will be sufficient. For instance, if your refactor involves changing syntax on top of untangling functionality, just update the code-style and move on. It may feel like taking a shortcut, but progress towards your refactoring goal is still progress. One day you will come back to rework this code, but today is not that day. Your efforts are better spent improving another part of your project.</p><h4>Push through to the end</h4><p>At some point you will start to see the light at the end of the tunnel — the refactor is nearly finished! That (long) list of tasks you set out at the beginning of the refactor project is dwindling down, and you can already see the fruits of your labour when adding new features to your project.</p><p>Don’t give up now! Put your efforts into finalising your refactor, cleaning up those last files and transforming functions. It may feel tedious after all the work you’ve already done, but tackling the last pieces you’ve been avoiding is just as important as everything which came before. And with your last commit you can start dreaming of what you can update next…</p><p>But first, bask in the glow of clean-code glory and pass me the champagne. Cheers, we did it! 🥂</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xqkqtio4w2UbSg5DCOtu6Q.png" /></figure><p><a href="http://eatwith.com/"><em>Eatwith</em></a><em> brings people together through food at tables all around the world. For more articles and insights from the tech &amp; product team, please subscribe to the </em><a href="https://medium.com/tech-eatwith"><em>Tech @ Eatwith</em></a><em> blog.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c69df8f2e7a7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tech-eatwith/untangling-the-code-refactor-c69df8f2e7a7">Untangling the code refactor</a> was originally published in <a href="https://medium.com/tech-eatwith">Tech @ Eatwith</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Storybook, Jest and the react-router Link]]></title>
            <link>https://medium.com/tech-eatwith/storybook-jest-and-the-react-router-link-cb4bc9859436?source=rss-c17dcd55928c------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb4bc9859436</guid>
            <category><![CDATA[react-router]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[storybook]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[jest]]></category>
            <dc:creator><![CDATA[Julia Mitchelmore]]></dc:creator>
            <pubDate>Fri, 03 Aug 2018 15:36:16 GMT</pubDate>
            <atom:updated>2018-11-13T15:46:52.143Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rxjDhNU_ejI1-dCuMKPGtw.jpeg" /></figure><p>At <a href="https://www.eatwith.com/">Eatwith</a>, we recently set up a component library to extract common elements used across our website, static pages and back-office platforms. To display the components, we chose to implement the <a href="https://github.com/storybooks/storybook">Storybook</a> framework with <a href="https://jestjs.io/">Jest</a> to run tests.</p><p>This set-up works well, however there are a few quirks which need to be navigated. One such is when you try to use a &lt;Link&gt; component within a Story or test, as the inherited router (which normally comes from the &lt;Provider&gt; wrapped around your app) doesn’t exist.</p><p>Here’s how to resolve that problem, so that you can include &lt;Link&gt;s in your component library as you would in your main project.</p><h3>With react-router v4</h3><p>Let’s assume that you’ve already created your Component.js, which includes a &lt;Link&gt; component imported from react-router-dom. You should also have installed react-router v4. When you go to write your first story about &lt;Component&gt; though, you’ll come across this big red error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bsavzjxJ3q8eOnjwDlN9IA.png" /></figure><p>Well, that’s pretty clear.</p><h4>Storybook</h4><p>To fix our stories, we’re going to add StoryRouter as a decorator for our story. This handy library will wrap around our story and expose the component to a mocked &lt;Router&gt;.</p><p>First, install the dependency:</p><pre>yarn add storybook-react-router</pre><p>Then inside your story, import StoryRouter and add the decorator, so that the file then looks something like this:</p><pre>import React from ‘react’</pre><pre>import { storiesOf } from ‘<a href="http://twitter.com/storybook/react">@storybook/react</a>’<br>import StoryRouter from ‘storybook-react-router’</pre><pre>import { Component } from ‘./Component’</pre><pre>const stories = storiesOf(‘Component’, module)</pre><pre>stories.addDecorator(StoryRouter())</pre><pre>stories.add(‘Example’, () =&gt; &lt;Component /&gt;)</pre><h4>Jest</h4><p>We need to implement a similar solution for our tests, to allow the &lt;Link&gt; to have access to a router. For this solution, we’ll be using another nifty library.</p><pre>yarn add react-mock-router</pre><p>As you can guess by the name, react-mock-router exposes a MockRouter component, which we will wrap around our own &lt;Component&gt;. To do so, add the following lines to your test file:</p><pre>import { mount } from ‘enzyme’<br>import MockRouter from ‘react-mock-router’</pre><pre>const mountWithRouter = (node) =&gt; mount(&lt;MockRouter&gt;{node}&lt;/MockRouter&gt;)</pre><p>Then in your test you would call mountWithRouter where normally you would call mount. You could also create a shallowWithRouter if you prefer to shallowly render your component.</p><pre>it(‘should render a Component’, () =&gt; {<br> const wrapper = mountWithRouter(&lt;Component /&gt;)<br> expect(toJson(wrapper)).toMatchSnapshot()<br>})</pre><p>And <em>voila</em>, our component with &lt;Link&gt; can now be tested properly.</p><h3>With react-router v3</h3><p>If your main app is still using react-router v3, unfortunately the above solution won’t work as the packages only support the latest version. But with a few tweaks to our code, all will be well.</p><p>In fact, react-router v3 includes all the features we need to expose our &lt;Component&gt; to the router within Storybook and in Jest tests, so there are no additional packages to install.</p><h4>Storybook</h4><p>To resolve our story errors, we’re going to create our own decorator which relies on `createMemoryHistory()` to build an empty router history. Add the following imports to your Storybook story</p><pre>import { Router, Route } from ‘react-router’<br>import createMemoryHistory from ‘react-router/lib/createMemoryHistory’</pre><p>and then build the decorator like so:</p><pre>const history = createMemoryHistory()</pre><pre>stories<br> .addDecorator(story =&gt; (<br>   &lt;Router history={history}&gt;<br>     &lt;Route path=”*” component={() =&gt; story()} /&gt;<br>   &lt;/Router&gt;<br> ))</pre><p><strong>Bonus: </strong><strong>react-router push events<br></strong>One of the main features of Storybook is the add-ons that give extra functionality to your stories. One such is actions, which logs defined actions to the Storybook console. It is commonly used to show that click events have fired correctly.</p><p>For our use-case, we can hook in to the router’s history which we exposed, and log the push event to our actions output. To do so, add the following import to your story (having already run yarn add @storybook/addon-actions to install the package)</p><pre>import { action } from ‘<a href="http://twitter.com/storybook/addon-actions">@storybook/addon-actions</a>’</pre><p>Then on the line below where we created our router history, we can define the action to be taken on the push event:</p><pre>const history = createMemoryHistory()<br>history.push = action(‘history.push’)</pre><p>Now whenever you click on the &lt;Link&gt; in your component, you will see the following logged to the console at the bottom of your Storybook story page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hCWCf6_VtDQaj3xb10u9-A.png" /></figure><h4>Jest</h4><p>For our tests, we’re going to use the jest.mock() function to replace all instances of the &lt;Link&gt; component with a standard anchor tag. This is as straightforward as adding the following line before you start describing your tests.</p><pre>jest.mock(‘react-router/lib/Link’, () =&gt; ‘a’)</pre><p>You can then just run your component library tests as normal.</p><p>All of these solutions exist somewhere on the internet, however I wanted to consolidate both approaches in one place for anyone facing the same problem of using react-router&#39;s &lt;Link&gt; within Storybook and Jest.</p><p>Hopefully this quick tutorial has been of use — if so, please clap or leave a comment below!</p><p><a href="http://eatwith.com/"><em>Eatwith</em></a><em> brings people together through food at tables all around the world. For more articles and insights from the tech &amp; product team, please subscribe to the </em><a href="https://medium.com/tech-eatwith"><em>Tech @ Eatwith</em></a><em> blog.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb4bc9859436" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tech-eatwith/storybook-jest-and-the-react-router-link-cb4bc9859436">Storybook, Jest and the react-router Link</a> was originally published in <a href="https://medium.com/tech-eatwith">Tech @ Eatwith</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>