<?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 Kartik Sharma on Medium]]></title>
        <description><![CDATA[Stories by Kartik Sharma on Medium]]></description>
        <link>https://medium.com/@starryfire?source=rss-2ccac03d12f4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*t7bcV66Mm0r2TMQw3hLmBw.jpeg</url>
            <title>Stories by Kartik Sharma on Medium</title>
            <link>https://medium.com/@starryfire?source=rss-2ccac03d12f4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 07:16:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@starryfire/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[Testing Your React Native App ( Part-1 )]]></title>
            <link>https://medium.com/squad-engineering/testing-your-react-native-app-part-1-7976af664075?source=rss-2ccac03d12f4------2</link>
            <guid isPermaLink="false">https://medium.com/p/7976af664075</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[Kartik Sharma]]></dc:creator>
            <pubDate>Mon, 21 Dec 2020 17:25:09 GMT</pubDate>
            <atom:updated>2020-12-22T08:04:34.335Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6S1wxPDEEmItyonUqCK8lA.jpeg" /></figure><h3>Introduction</h3><p>Most developers find testing boring and a pain to write, but you know what? It takes great skill and experience to know how to write meaningful and maintainable tests. The knowledge that you gain from learning how to test your code will also change the way you write code in development. This article should help you get started on your journey of testing.</p><h3>Guidelines For Better Testing</h3><p>These are some of the guidelines I learned after researching how other developers are testing their code. Following these guidelines made it easier for me to write and maintain tests throughout the codebase.</p><h4>1. Don’t test the implementation of your code</h4><p>To understand why this is important, let’s go through a scenario. Suppose you wrote a function that takes <strong>n</strong> as an input and outputs the result of adding the first <strong>n </strong>numbers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c25b50d38b27173b80cd3b2f71d80ca/href">https://medium.com/media/0c25b50d38b27173b80cd3b2f71d80ca/href</a></iframe><p>Let’s assume that you are testing getSumOfFirstN for n=2 by asserting that add is called 2 times with the arguments (0, 2) and (2, 1) respectively and the output of getSumOfFirstN is 3.</p><p>Later, you find out that there is a better way to find the sum of first <strong>n </strong>numbers and rewrite the above code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ba38da6cf5d6879e918f186a753eb7c/href">https://medium.com/media/9ba38da6cf5d6879e918f186a753eb7c/href</a></iframe><p>Your test will start breaking because you are no longer calling add</p><p>This was a straightforward example, and that’s why it might seem counter-intuitive, but I have seen a lot of developers doing exactly this kind of testing where the mistake is not so easy to see.</p><h4>2. Don’t let your tests become another tech-debt</h4><p>Testing is important, but you also need to be delivering the code to the relevant stakeholders on time. If whenever you write a new feature or modify an existing one, it breaks your old test cases or you end up spending a significant amount of your allocated time on fixing old test cases rather than building the required features, then ultimately you will end up deleting all the old tests and risk the project to fail in production.</p><p>Following these guidelines should help you in ensuring that your tests are either easily fixable or don’t break at all when your codebase changes.</p><h4>3. When testing UI, write tests in a way that simulates actual user behaviour.</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18ad161f27a77f407a56e9974cca96a3/href">https://medium.com/media/18ad161f27a77f407a56e9974cca96a3/href</a></iframe><p>Suppose you are testing whether this button was rendered and working as expected or not then first think about how the user would find and interact with this button. I am hoping that they would see the “Submit” text and then press on it and so that’s exactly what we would simulate. In our test case, we will first search for the text “Submit” and then simulate the “onPress” event on it and then assert whatever that was supposed to do.</p><p>In some cases, it might not be easy to uniquely identify the component that you want to target, and in that case, you can use testID prop but remember that you will not be simulating the full user behaviour if you use testID because users don’t target components based on their testID .</p><p>Why is this important? Why must we try to simulate user behaviour as much as possible when testing UI? This is because in the end, it will be a human that will be interacting with your UI and not a computer and if they see a “Hello” being rendered in your button rather than a “Submit”, your test case should be failing because that is something that can throw the end user off.</p><h4>4. Pure functions are easier to test than impure functions</h4><p>Pure functions are functions that will always give the same output for a corresponding input, i.e. if a pure function pumps out 2 for a 1 then it would always do that whereas impure functions might pump-out 2 on the first call and then pump-out 5 on the second call.</p><p>This is handy to keep in mind when writing code. Impure functions can become easier to test if the module that is introducing the “impurity” in such functions is mockable.</p><h4>5. Use fixtures as input and assertions in your tests</h4><p>Suppose you have an object of type employee and you have various functions operating on them such as a function to capitalize the name , a function to check whether the employee is an adult or not, etc.</p><p>Now, suppose you take this object as input in all your test cases.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/61591744ad65e00baf153366f9bad6c9/href">https://medium.com/media/61591744ad65e00baf153366f9bad6c9/href</a></iframe><p>This is your dummy data or your “fixture”. In your first test case that tests whether the function that capitalizes the name is working as expected or not, you assert that it’s output is equal to { ...employee, name: employee.name.toUpperCase() } and in your second test case, you assert whether the function outputs employee.age &gt;= 18 or not, and so on.</p><p>You might be wondering what advantage do we get by using fixtures in such a way? The answer is that you are making it easier for yourself to fix tests quickly in the future by writing your tests this way.</p><p>E.g. What if we want to add another property maritalStatus in the employee object because now all our employees are required to disclose their marital status. If in our first test case, we asserted the output to be equal to { name: &quot;KARTIK&quot;, age: 25, sex: &quot;Male&quot;, children: 0 } instead of { ...employee, name: employee.name.toUpperCase() } , our test case will break. It will also break if we change the value of name to something else. In other words, our test case would not be flexible at all and hence will have a higher chance of breaking due to unrelated changes in the codebase.</p><h4>6. Write unit tests for components and utility functions</h4><p>These are parts of your code that are going to be used by multiple modules. Hence, they need to be tested for all possible inputs / edge-cases because you don’t know how the other modules are going to be using these functions/components. Hence, these should not have any unexpected behaviour.</p><h4>7. Write integration tests for screens</h4><p>It’s hard to write unit tests for screens because usually, these depend on a large number of components and other third party libraries like a redux store. So, to write unit tests for screens, you will first have to mock all these dependencies, which is a lot of work. This is why it’s better to write integration tests in this case.</p><h4>7. Write E2E tests for testing native code</h4><p>Native code does not run in a jest environment. So to test it, you will have to use a library like Detox.</p><h4>8. Always do snapshot testing for screens and components</h4><p>If you make a style change in a component that is being used by multiple other screens/components, then the snapshot tests for those will fail until you update the snapshots. It will help you understand which other modules were affected by the change that you made. If you are working in a team, it really helps the reviewer during PR reviews understand what modules were affected by the particular change you made in the component because the changes in the snapshots of those modules are reflected in your PR.</p><h3>Conclusion</h3><p>I hope you found this article helpful and if you are confused by what you just read then don’t worry. The second part of this series will be a tutorial on setting up the testing environment in React Native with code examples of testing screens, components, and functions, following the guidelines that we have set in this first part.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7976af664075" width="1" height="1" alt=""><hr><p><a href="https://medium.com/squad-engineering/testing-your-react-native-app-part-1-7976af664075">Testing Your React Native App ( Part-1 )</a> was originally published in <a href="https://medium.com/squad-engineering">SquadStack Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Folder Structure For React / React Native]]></title>
            <link>https://blog.devgenius.io/folder-structure-for-react-react-native-6f62344e084e?source=rss-2ccac03d12f4------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f62344e084e</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[folder-structure]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Kartik Sharma]]></dc:creator>
            <pubDate>Sat, 04 Jul 2020 19:18:36 GMT</pubDate>
            <atom:updated>2020-07-07T07:27:25.986Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to structure your react project for better scalability &amp; maintainability</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fWPTwnLBSgrKVb3uqAvdvw.jpeg" /><figcaption>Structuring Your Project Is Like Playing Jenga :P</figcaption></figure><h3>Introduction</h3><p>It’s been three months since i started working with React Native, and before that i had been working with React for over a year. I remember when i was starting out with my first React Native project that i didn’t want to repeat the same mistakes i did with my previous React project.</p><p>The previous project was not following a strict folder structure from the get-go and when one team member took some decision regarding the folder structure, the rest of the team was not informed. This lead to chaos and rewrites that could have been easily avoided.</p><p>This article summarises why a properly defined folder structure is very important, especially for React / React Native projects and then we will discuss the folder structure that i personally have been following for the past 3 months.</p><h3>What Importance Does A Good Folder Structure Hold For Your Project?</h3><p>When you start working with large-scale projects, which usually has multiple programmers working on it, you can easily lose track of code written by you or by your team member as the project scales with time. This is especially true for React based projects where we can all agree that the number of lines in the codebase increases at an alarming rate everyday depending on your team size and workload. In such an environment, one should especially give importance to code maintainability.</p><p>Code that should have been a screen/container becomes a component and vice-versa. This leads to bad design and confusion later on as to what should be what, when it should have been clear from the very start.</p><p>Business logic gets mixed with UI logic which is really bad. You might not realise when you first start your project how important it is to keep those two separate because as the project scales UI logic can easily take hundreds of lines of code in a file and we can say the same for business logic. Would you like it if i told you to make a change in a file that spans over a thousand line of code and doesn’t even have a clear distinction between business and UI logic? Exactly.</p><p>I can go on and on about why a good folder structure is important but lets stop here and move onto the next part of the article.</p><h3>Folder Structure</h3><pre>MY-APP<br>├── envs<br>├── scripts<br>└── src<br>    ├── services<br>    ├── state<br>    ├── utils<br>    └── views </pre><p><strong>Environments</strong></p><p>If you are planning to run your project in different environments i.e. debug , staging and production . You would need a place to store your different .env files and that is what the envs folder is used for.</p><pre>envs<br>├── .env.debug<br>├── .env.staging<br>└── .env.release</pre><p><strong>Scripts</strong></p><p>We run some pre-commit scripts on every commit and store those scripts in scripts folder.</p><p><strong>Services</strong></p><p>This is where we store the classes that handle our API calls, error reporting and wrappers for third party services like moment.js , uxcam, axios etc.</p><pre>services<br>├── api<br>├── http<br>├── sentry<br>...</pre><p><strong>State</strong></p><p>This is where we store all our business logic i.e. validations, api requests, what happens on a button click, etc.</p><p>We are using Redux and Redux-Sagas in our project and handle business logic using them. This helps us keep our view and business logic separate and helps us avoid clutter as the project scales. You don’t want to write asynchronous code in the same file as your React code, believe me.</p><pre>state<br>├── ducks<br>│   ├── Feature/Screen<br>│   │   ├── actions.js<br>│   │   ├── constants.js<br>│   │   ├── reducer.js<br>│   │   ├── sagas.js<br>│   │   ├── selectors.js<br>│   │   └── types.js<br>│   │   <br>│   │<br>│   ...<br>│<br>├── rootReducer.js<br>├── rootSaga.js<br>└── store.js</pre><p>If you noticed, we are using a folder structure inspired from <a href="https://www.freecodecamp.org/news/scaling-your-redux-app-with-ducks-6115955638be/">re-ducks folder structure</a>, which we personally like very much!</p><p><strong>Views</strong></p><p>This is where we store our UI logic i.e. our components, screens, hocs, custom hooks, etc.</p><pre>views<br>├── assets<br>│   ├── animations<br>│   ├── fonts<br>│   └── images<br>│<br>├── components<br>├── hocs<br>├── screens<br>├── hooks<br>└── configs<br>    ├── colors.js<br>    ├── spacings.js<br>    ├── styles.js<br>    └── typography.js</pre><p>In configs , we store what colors, font families, global stylesheets, values of medium/large/etc. spacings, base font size, etc. we are using throughout our project. Its a good practice to keep all these configurations in one place and reference them from there only.</p><h3>Wrapping Up</h3><p>I hope you learned something from this article and figured how to structure your brand new or existing React project.</p><p>I wish i could have gone much deeper into every part of this article but then we would have strayed from the original purpose of it.</p><p>This was my first attempt at an article and a way of expressing thanks to the medium and open-source community for helping me figure things out whenever i was in a pinch!</p><p>If you want me to write more articles on React / React Native. Do ping me, i would be happy to contribute more to this wonderful community :)</p><p><strong>If you found this article helpful, don’t forget to share and clap!</strong> 👏</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f62344e084e" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/folder-structure-for-react-react-native-6f62344e084e">Folder Structure For React / React Native</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>