<?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 Shanaka &#39;Sha&#39; Senevirathne on Medium]]></title>
        <description><![CDATA[Stories by Shanaka &#39;Sha&#39; Senevirathne on Medium]]></description>
        <link>https://medium.com/@hdsenevi?source=rss-96318920710b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*T0rgr4UUFDciwz-Z_vGyZg.jpeg</url>
            <title>Stories by Shanaka &amp;#39;Sha&amp;#39; Senevirathne on Medium</title>
            <link>https://medium.com/@hdsenevi?source=rss-96318920710b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 11:39:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hdsenevi/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[xcode-select error once xcode is uninstalled]]></title>
            <link>https://medium.com/@hdsenevi/xcode-select-error-once-xcode-is-uninstalled-4c3e23fdfb92?source=rss-96318920710b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c3e23fdfb92</guid>
            <dc:creator><![CDATA[Shanaka 'Sha' Senevirathne]]></dc:creator>
            <pubDate>Sun, 25 Sep 2022 07:31:07 GMT</pubDate>
            <atom:updated>2022-09-25T07:32:51.157Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="computer terminal commands displayed on a dark computuer background with bright green text" src="https://cdn-images-1.medium.com/max/1024/0*Uh5UOsroN3os-BfT" /><figcaption>Photo by <a href="https://unsplash.com/@jakewalker?utm_source=medium&amp;utm_medium=referral">Jake Walker</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>TL;DR</h3><p>If you are getting the following error after uninstalling xcode</p><pre>xcrun: error: active developer path (&quot;/Applications/Xcode.app/Contents/Developer&quot;) does not exist</pre><p>Try this</p><pre>sudo xcode-select --reset</pre><p>Xcode was taking too much space on your mac. It’s beside the fact that I had a lot of other cruft on my mac at the time. Regardless, I decided to uninstall xcode as I will have to install the latest xcode after the beta is out.</p><p>While I was in limbo after uninstalling and before re-installing a new xcode I was doing some node work and came across this error. I encounted this when I was trying to use git</p><h4>Problem</h4><pre>xcrun: error: active developer path (&quot;/Applications/Xcode.app/Contents/Developer&quot;) does not exist</pre><pre>Use `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools, or use `xcode-select --install` to install the standalone command line developer tools.</pre><pre>See `man xcode-select` for more details.</pre><h4>Solution</h4><p>Reset xcode-select like so</p><pre>sudo xcode-select --reset</pre><p>You might want to install xcode-select if it’s not already installed on your system before running the above --reset</p><pre>xcode-select --install</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c3e23fdfb92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to fix pod install breaking your iOS project]]></title>
            <link>https://medium.com/@hdsenevi/how-to-fix-pod-install-breaking-your-ios-project-57a7c1c64441?source=rss-96318920710b------2</link>
            <guid isPermaLink="false">https://medium.com/p/57a7c1c64441</guid>
            <category><![CDATA[objective-c]]></category>
            <category><![CDATA[cocoapods]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Shanaka 'Sha' Senevirathne]]></dc:creator>
            <pubDate>Tue, 22 Jan 2019 21:56:39 GMT</pubDate>
            <atom:updated>2019-01-22T21:56:39.561Z</atom:updated>
            <content:encoded><![CDATA[<p>If you have a <a href="https://cocoapods.org/">CocoaPods</a> integrated iOS app and when you do pod install if your .xcodeproj file becomes un-openable then this article is for you. (maybe)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9d1fqk9Dj4R-FMJf" /><figcaption>Photo by <a href="https://unsplash.com/@saimiri_sciureus?utm_source=medium&amp;utm_medium=referral">Fabienne Hübener</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>TL;DR</h3><p>Remove the following entry from your Podfile and do a pod install. Dance when it all works and does not break .xcodeproj file.</p><pre>install! &#39;cocoapods&#39;, :deterministic_uuids =&gt; <strong>false</strong></pre><h3>The juicy details</h3><p>This scenario will not apply to most. But if it does, you can thank me in the comments section for providing the solution 😄</p><p>At work, we had a perfectly working iOS project (react-native, but thats beside the point). This was when xCode 9.4.1 was the new kind on the block. So everything was hunky dory and life was good. This was the general structure of the PodFile we had.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/515e0d95cb8d86bcfb74e88deecdc1fe/href">https://medium.com/media/515e0d95cb8d86bcfb74e88deecdc1fe/href</a></iframe><p>There is nothing out of the extraordinary here and we aren’t doing anything fancy with it either. It’s a straight forward Podfile.</p><h3>The problem</h3><p>So we were presently surprise when everything broke when we tried to do pod install all of a sudden.</p><p>The problem was a bit complicated in the sense that we could do a pod install with the already integrated Podfile and nothing would break. But as soon as we try to include a new pod to the mix then 💥</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*1PbKkMghDTVIJCY7TuzP7w.png" /><figcaption>What we get when we do a `pod install` and open .xcworkspace and try to select .xcodeproj</figcaption></figure><h3>The solution</h3><p>Turns out, removing the following line from the Podfile fixed our issue</p><pre>install! &#39;cocoapods&#39;, :deterministic_uuids =&gt; <strong>false</strong></pre><blockquote>More precisely not having deterministic_uuids is what got us at the end</blockquote><p>We shouldn’t have had above line of code in our Podfile to begin with for various reasons</p><ol><li>Having ‘cocoapods’ in the <a href="https://guides.cocoapods.org/syntax/podfile.html#group_root_options">Root Options</a> is unnecessary as it’s the ONLY accepted installation method at the moment.</li><li>Creating a new Podfile using pod init does not generate this line of code</li><li><a href="https://guides.cocoapods.org/syntax/podfile.html#install_bang">Default value</a> for deterministic_uuids is true</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1SYX3QS4DIu9Cr3B" /><figcaption>Photo by <a href="https://unsplash.com/@rawpixel?utm_source=medium&amp;utm_medium=referral">rawpixel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57a7c1c64441" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unit testing in React Native with Jest and Enzyme]]></title>
            <link>https://medium.com/@hdsenevi/unit-testing-in-react-native-with-jest-and-enzyme-40cd7dabb6f1?source=rss-96318920710b------2</link>
            <guid isPermaLink="false">https://medium.com/p/40cd7dabb6f1</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[jest]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[enzyme]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Shanaka 'Sha' Senevirathne]]></dc:creator>
            <pubDate>Tue, 11 Dec 2018 13:30:33 GMT</pubDate>
            <atom:updated>2018-12-13T13:49:34.623Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-TOJUXkpSPwK67jGsZPeTw.png" /><figcaption>React Native + Jest + Enzyme 👏</figcaption></figure><p>Unit testing is the first line of defence for your codebase and is key to a healthy and maintainable app.</p><blockquote>If you don’t like testing your product, most likely your customers won’t like to test it either. — <em>Grasshopper</em></blockquote><p>There is a reason why unit tests makes the base of the <strong><em>Testing Triangle</em></strong>. Idea here is, more tests needs to be written at the bottom of the triangle and less and less tests when we move up on the triangle. So more unit tests than integration test etc etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*i2dyL9EKNqfjQpW6pNGbSA.jpeg" /><figcaption>Famous Testing triangle</figcaption></figure><h4>What are we unit testing exactly?</h4><p>When unit testing, we are checking the smallest <strong>unit</strong> in our codebase to find out how happy, unhappy and edge cases work for that piece of <strong>unit</strong>. For example, a <strong>unit</strong> could be individual methods and functions in classes or really any small pieces of functionality. We mock out dependencies in these tests so that we can test individual methods and functions in isolation.</p><h4>What frameworks do we use?</h4><p>These test are written using testing frameworks and for this article we will be using <a href="https://jestjs.io/">Jest</a>, Facebooks javascript testing framework together with <a href="https://airbnb.io/enzyme/">Enzyme</a>, Airbnb’s testing utility for React.</p><h3>Configure Jest and Enzyme</h3><p>Let’s start from scratch and create a new react-native app. Refer to <a href="https://facebook.github.io/react-native/docs/getting-started.html">Getting Started — React Native</a> for setup instructions.</p><p>Jest comes out of the box so let install Enzyme. Refer to <a href="https://airbnb.io/enzyme/">Enzyme install instructions</a> for further info</p><p>Install enzyme dev dependancies by opening up a terminal session in project root directory and executing the following command in it. I’ll refer to this folder as <strong><em>rootDir</em></strong> from here onwards.</p><pre>npm i — save-dev enzyme enzyme-adapter-react-16 react-dom</pre><p>Create a jest.config.json file in <strong><em>rootDir</em></strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/067f978e1f5cfe3a527fdc12ae1940c7/href">https://medium.com/media/067f978e1f5cfe3a527fdc12ae1940c7/href</a></iframe><p>Refer to <a href="https://jestjs.io/docs/en/configuration.html">Jest configuration guide</a> for more info on the available options</p><p>Create a folder called <strong><em>jest</em></strong> inside <strong><em>rootDir</em></strong> and then create setup.js file in <strong><em>rootDir/jest/</em></strong> folder.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa0941bffcb662e1d194a6f20f44f544/href">https://medium.com/media/fa0941bffcb662e1d194a6f20f44f544/href</a></iframe><p>Now we are all set to start unit testing in React Native with Jest and Enzyme.🎉 😎 🎊</p><h3>Taking a snapshot in time 📸</h3><h4>What is snapshot testing?</h4><p>With Jest we have a very easy way to test if a component is rendered correctly given certain props and state. It’s called <a href="https://jestjs.io/docs/en/snapshot-testing">snapshot testing.</a></p><blockquote>A good snapshot stops a moment from running away — Eudora Welty</blockquote><blockquote>Snapshot tests are a very useful tool whenever you want to make sure your UI does not change unexpectedly.</blockquote><blockquote>A typical snapshot test case for a mobile app renders a UI component, takes a screenshot, then compares it to a reference image stored alongside the test. The test will fail if the two images do not match: either the change is unexpected, or the screenshot needs to be updated to the new version of the UI component.</blockquote><h4>Basics of snapshot testing</h4><p>Lets setup a basic <strong>button</strong> component so that we try out snapshot testing it.</p><p>Create a <strong>Button.js</strong> file under <strong><em>rootDir/src</em></strong><em> folder</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f1ef862be1784acc098320d8b4cafda/href">https://medium.com/media/8f1ef862be1784acc098320d8b4cafda/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*nCkIx2kuYqudSlGX8UJalQ.png" /><figcaption>Button will look like this when rendered</figcaption></figure><p>Now let’s create the test (sometimes called spec) file. Create <strong>Button.test.js</strong></p><blockquote>Alternatively you can call this file Button.<strong>spec</strong>.js as well. Jest will accept both extensions and will append file extension as necessary for auto generated files such as snapshots.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5be4029e6af50afbc88addb99b6c10a/href">https://medium.com/media/a5be4029e6af50afbc88addb99b6c10a/href</a></iframe><p>In this case we have used Enzyme’s <a href="https://airbnb.io/enzyme/docs/api/shallow.html">shallow</a> rendering to help us create a snapshot.</p><h4>Running tests</h4><p>It’s time to execute your test. We do this by invoking the following.</p><pre>npm run test</pre><p>Since this is the first time we run this snapshot test, Jest will create a snapshot file for us inside the folder <strong><em>__snapshots__</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*cG670PVZ4lxOUovLe0ZVBA.png" /><figcaption>Folder structure</figcaption></figure><h4>What happens when something changes?</h4><p>The usefulness of snapshots come into play when you (or someone else) changes a presentational aspect of this component. As an example try changing fontSize to something other than 16 in <strong>Button.js</strong> and run tests again. You will see an error like the following.</p><pre>Received value does not match stored snapshot</pre><p>Which means, we have changed the way how this component gets rendered. If this is intentional, we can update the snapshot by passing in the flag <strong>-u</strong> to <strong>npm run test</strong> like so</p><pre>npm run test -- -u</pre><p>If the change is not intentional, that means we have done a change unintentionally that will change the way this component gets rendered. So we will have to go ahead and revert our change.</p><p>I’ve changed the <strong>Button.js</strong> to be</p><ol><li>Class based component</li><li>Custom function is invoked when onPress is tapped</li><li>Change color of button depending on ‘primary’ prop</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f849d0400d2259f20018875aafc80b5/href">https://medium.com/media/7f849d0400d2259f20018875aafc80b5/href</a></iframe><p>Lets test this puppy by running the tests and updating snapshots (thats npm run test -- -u if you forgot)</p><h4>Coverage report</h4><p>When we run tests, jest generates a nice coverage report for us. To have a look at it, navigate to <strong><em>rootDir/coverage/lcov-report/index.html</em></strong><em>.</em></p><p>Clicking on Button.js will reveal the coverage visually. From this we can deduce what <strong><em>statements/branches not covered</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fd8gWNUxAf0DXsd7JQXeSQ.png" /><figcaption>Coverage report visually shows issues</figcaption></figure><p>On line 24, <strong><em>branch not covered</em></strong> comes up because we are setting default value for primary props to be true in <strong>Button </strong>component. And in <strong>Button.test.js</strong> we don’t pass in a prop for primary so the default value gets used.</p><pre>const component <strong>=</strong> shallow(&lt;Button label<strong>=</strong>&quot;test label&quot;/&gt;)</pre><p>Change <strong>Button.test.js</strong> to remedy this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/904a1ad068cfdb095abbc88ec9a1860b/href">https://medium.com/media/904a1ad068cfdb095abbc88ec9a1860b/href</a></iframe><p>Now all that is left is to test onPressHandler function. But for us to do that, we need to talk about <a href="https://jestjs.io/docs/en/mock-function-api.html">mocking</a> 😮</p><h3>Don’t mock me 🐒</h3><p>The idea behind <a href="https://jestjs.io/docs/en/mock-function-api.html">mocking</a> is to replace something we don’t control with something we do.</p><blockquote>Mock functions are also known as “spies”, because they let you spy on the behaviour of a function that is called indirectly by some other code, rather than just testing the output.</blockquote><p>Lets focus on two ways Jest helps us out with mocking</p><ul><li>jest.fn() — mock function</li><li>jest.mock() — mock module</li></ul><h4>Mocking functions with jest.fn()</h4><p>jest.fn() provides ways to capture calls, set return values and change implementation of a function. Refer to <a href="https://jestjs.io/docs/en/mock-function-api.html">Jest mock function api</a> for further information.</p><p>Let’s user jest.fn() to test if onPress is getting called inside onPressHandler()</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/449654d9ac49f62496391766b46bf14f/href">https://medium.com/media/449654d9ac49f62496391766b46bf14f/href</a></iframe><ol><li>Mocking function with instance of a jest function.</li><li>Passing in mock function as a prop (as onPress). Upon onPress we expect the mock function to get called.</li><li>Manually calling onPressHandler()</li><li>Checking if mock function gets called and how many times</li></ol><h4>Mocking modules with jest.mock()</h4><p>jest.mock() is the module mocking solution from Jest.</p><p>Let’s use it to see if Linking.openURL() is getting called or not and in what circumstances.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dfd65b5be68cac5dacaefec7830c86f7/href">https://medium.com/media/dfd65b5be68cac5dacaefec7830c86f7/href</a></iframe><ol><li>Set openURL module function to jest.fn</li><li>Preparing a reusable shallow rendered instance so that we don’t repeat ourselves trying to create the same shallow instance with the same props</li><li>mockOpenURL should be called since we have passed in ‘url’ prop</li><li>mockOpenURL should NOT be called as we have NOT passed in ‘url’ prop</li></ol><h3>Anatomy of a unit test</h3><p>There are few different ways to structure your unit test. The most common pattern being AAA (Arrange Act Assert).</p><p>Idea is to seperate your test into the said three sections so that it’s easier to reason about the test.</p><h3>Some good practices 🏃</h3><h4><em>It’s important to write testable code in the first place.</em></h4><p>Unit testing should begins before we actually write any tests. Writing testable code is as (if not more) important as writing unit tests themselves.</p><h4><em>Only unit test one piece of code / function at a time.</em></h4><p>Don’t try to unit test a scenario where you call an api and then it resolves and set a state and based off on that state the component renders something different.</p><p>Rather, unit test those different units on their own. Check function that calls the api and test upon resolve/reject what state it sets. Then in another test check given this state how does a component render.</p><h4>Given a certain input, whats the output?</h4><p>Thinking in these terms will make reasoning about what and how to unit test much easier.</p><h4>AAA (Arrange, Act, Assert) pattern</h4><p>It also helps to think in terms of AAA (Arrange, Act, Assert) pattern when you are starting off writing test as it gives a clear separation of concert for the structure of your tests.</p><h3>Wrap up</h3><p>These are few basic ways you can start unit testing your React Native codebase with <a href="https://jestjs.io/docs/en/getting-started">Jest</a> and <a href="https://airbnb.io/enzyme/">Enzyme</a>. They both have great documentation so there is no reason you should not unit test your codebase anymore. ⭐️ 🌟 ✨</p><p>Thank you for talking time to read this story!. If you enjoyed it and/or found it useful please leave a 👏. If not, please leave a comment and let me know what I can improve for the next one. Happy unit testing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Sauye5wQRLuS5gnf" /><figcaption>Photo by <a href="https://unsplash.com/@vimarovi?utm_source=medium&amp;utm_medium=referral">Victor Rodriguez</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Edit 14 Dec 2018</strong> : Rectified an issue in the <strong>Configure Jest and Enzyme</strong> section.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40cd7dabb6f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>