<?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 Dmytro Manhura 🇺🇦 on Medium]]></title>
        <description><![CDATA[Stories by Dmytro Manhura 🇺🇦 on Medium]]></description>
        <link>https://medium.com/@manguradima?source=rss-1044e8315cf5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*645x7mE9tkwM7ue47hjIlg.jpeg</url>
            <title>Stories by Dmytro Manhura 🇺🇦 on Medium</title>
            <link>https://medium.com/@manguradima?source=rss-1044e8315cf5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 13:56:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@manguradima/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[How to optimize your unit tests. Don’t repeat yourself.]]></title>
            <link>https://medium.com/@manguradima/how-to-optimize-your-unit-tests-dont-repeat-yourself-902599669fc8?source=rss-1044e8315cf5------2</link>
            <guid isPermaLink="false">https://medium.com/p/902599669fc8</guid>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[jest]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Dmytro Manhura ]]></dc:creator>
            <pubDate>Mon, 12 Jun 2023 19:06:19 GMT</pubDate>
            <atom:updated>2023-06-12T19:07:12.412Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cehpeHbFQRMSRiDTpjFbSg.jpeg" /><figcaption>Baby maltipoo</figcaption></figure><p>Today I’m going to discuss unit tests and how to make them better. We will look at a few examples of improving unit tests and removing duplicates in the code. I will use <a href="https://jestjs.io/">jest</a> for testing, and the function for testing will be written on javascript without any additional frameworks or libraries.</p><p>In real-world projects, you will definitely have a crucial function that is not-easy-to-change. But of course, you will have to change it. It would be great if, before changing it, you already have a unit test for it. But it is not a problem for us now. I will provide potential initial tests, and we will try to improve them.</p><h3><strong>Function for testing</strong></h3><p>Let’s imagine we have a function that accepts a string as a parameter, validates this string, and returns a boolean. It can be a function that validates names and accepts only Latin letters, and it can look like this.</p><pre>const validateName = (name) =&gt; {<br>  // Some code<br>  const isLatin = ...;<br>  <br>  if (isLatin) {<br>    return true;<br>  }<br><br>  return false;<br>};</pre><h3><strong>Initial unit tests</strong></h3><p>Mostly, developers try to cover only happy paths. Often the main aim of testing is the coverage. This kind of test will not help developers to prevent bugs during refactoring.</p><pre>import { validateName } from &#39;./validator.js&#39;;<br><br>it(&#39;validateName() - should return valid value&#39;, () =&gt; {<br>  expect(validateName(&#39;l&#39;)).toBe(true);<br>  expect(validateName(&#39;a&#39;)).toBe(true);<br>  expect(validateName(&#39;c&#39;)).toBe(true);<br>  expect(validateName(&#39;л&#39;)).toBe(false);<br>  expect(validateName(&#39;㐎&#39;)).toBe(false);<br>  expect(validateName(&#39;ـب&#39;)).toBe(false);<br>});</pre><p>But it’s not enough if you want to be more confident. You have to cover more cases, such as:</p><ol><li>All Latin letters.</li><li>As much as possible other alphabets.</li><li>Names with special characters.</li><li>Names with letters from a mix of alphabets.</li><li>All names in the production database.</li></ol><p>If you use the same approach for writing unit tests as we used above, your tests will become a total mess. Your file will be huge, and it will not be easy to define what’s wrong with your function.</p><pre>import { validateName } from &#39;./validator.js&#39;;<br><br>it(&#39;validateName() - should return valid value&#39;, () =&gt; {<br>  // List of all Latin letters <br>  expect(validateName(&#39;l&#39;)).toBe(true);<br>  expect(validateName(&#39;a&#39;)).toBe(true);<br>  expect(validateName(&#39;c&#39;)).toBe(true);<br>  ... <br>  // List of all accepted symbols<br>  expect(validateName(&#39;-&#39;)).toBe(true);<br>  ...<br>  // List of all not accepted symbols<br>  expect(validateName(&#39;*&#39;)).toBe(false);<br>  ...<br>  // All names in the production database<br>  expect(validateName(&#39;Alex&#39;)).toBe(true);<br>  expect(validateName(&#39;David&#39;)).toBe(true);<br>  ...<br>  // Cyrillic<br>  expect(validateName(&#39;л&#39;)).toBe(false);<br>  expect(validateName(&#39;Д&#39;)).toBe(false);<br>  ... <br>  // Korean <br>  expect(validateName(&#39;㐎&#39;)).toBe(false);<br>  ...<br>  // Arabic<br>  expect(validateName(&#39;ـب&#39;)).toBe(false);<br>  ... <br>  // Names with letters from a mix of alphabets.<br>  expect(validateName(&#39;Alex-Алекс&#39;)).toBe(false);<br>  ...<br>});</pre><h3><strong>Refactoring</strong></h3><p>First of all, we can group similar tests and provide self-explained descriptions. Grouping tests will help catch the problem’s route faster and provide documentation for your function. New developers will easily understand what this function does and be more confident with changing it.</p><pre>import { validateName } from &#39;./validator.js&#39;;<br><br>describe(&#39;validateName()&#39;, () =&gt; {<br>  it(&#39;All latin letters should be accepted.&#39;, () =&gt; {<br>    // List of all Latin letters<br>    expect(validateName(&#39;l&#39;)).toBe(true);<br>    expect(validateName(&#39;a&#39;)).toBe(true);<br>    expect(validateName(&#39;c&#39;)).toBe(true);<br>    ...<br>  });<br>  <br>  it(&#39;Some symbols should be accepted.&#39;, () =&gt; {<br>    // List of all accepted symbols<br>    expect(validateName(&#39;-&#39;)).toBe(true);<br>    ...<br>  });<br><br>  it(&#39;Some symbols should not be accepted.&#39;, () =&gt; {<br>    // List of all not accepted symbols<br>    expect(validateName(&#39;*&#39;)).toBe(false);<br>    ...<br>  });<br><br>  it(&#39;All names in the production database should be accepted.&#39;, () =&gt; {<br>    // All names in the production database<br>    expect(validateName(&#39;Alex&#39;)).toBe(true);<br>    expect(validateName(&#39;David&#39;)).toBe(true);<br>    ...<br>  });<br>  <br>  it(&#39;All korean letters should not be accepted.&#39;, () =&gt; {<br>    // Korean <br>    expect(validateName(&#39;㐎&#39;)).toBe(false);<br>    ...<br>  });<br> <br>  it(&#39;Names with letters from a mix of alphabets should not be accepted.&#39;, () =&gt; {<br>    expect(validateName(&#39;Alex-Алекс&#39;)).toBe(false);<br>  });<br>})</pre><p>To avoid code duplications in the test file, we can define new arrays for all our groups of symbols and letters and go through all items inside these arrays using forEach. In this step, we deleted a lot of duplicates but saved grouping at the same time.</p><pre>import { validateName } from &#39;./validator.js&#39;;<br><br>const latinLetters = [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, ...];<br>const acceptedSymbols = [&#39;-&#39;, ...];<br>const notAcceptedSymbols = [&#39;$&#39;, &#39;*&#39;, &#39;(&#39;, &#39;)&#39;, ...];<br>const cyrilicLetters = [&#39;а&#39;, &#39;б&#39;, &#39;в&#39;, &#39;г&#39;, ...];<br>const koreanLetters = [&#39;ㅊ&#39;, &#39;ㅋ&#39;, &#39;ㅍ&#39;, &#39;ㅎ&#39;, ...];<br><br>describe(&#39;validateName()&#39;, () =&gt; {<br>  describe(&#39;All latin letters should be accepted.&#39;, () =&gt; {<br>    latinLetters.forEach((letter) =&gt; {<br>      it(`Letter ${letter} should be accepted.`, () =&gt; {<br>        expect(validateName(letter)).toBe(true);<br>      });<br>    });<br>  });<br><br>  describe(&#39;Some symbols should be accepted.&#39;, () =&gt; {<br>    acceptedSymbols.forEach((symbol) =&gt; {<br>      it(`Symbol ${symbol} should be accepted.`, () =&gt; {<br>        expect(validateName(symbol)).toBe(true);<br>      })<br>    });<br>  });<br><br>  describe(&#39;Some symbols should not be accepted.&#39;, () =&gt; {<br>    notAcceptedSymbols.forEach((symbol) =&gt; {<br>      it(`Symbol ${symbol} should be accepted.`, () =&gt; {<br>        expect(validateName(symbol)).toBe(false);<br>      })<br>    });<br>  });<br><br>  describe(&#39;All cyrilic letters should not be accepted.&#39;, () =&gt; {<br>    cyrilicLetters.forEach((letter) =&gt; {<br>      it(`Letter ${letter} should not be accepted.`, () =&gt; {<br>        expect(validateName(letter)).toBe(false);<br>      });<br>    });<br>  });<br><br>  describe(&#39;All korean letters should not be accepted.&#39;, () =&gt; {<br>    koreanLetters.forEach((letter) =&gt; {<br>      it(`Letter ${letter} should not be accepted.`, () =&gt; {<br>        expect(validateName(letter)).toBe(false);<br>      });<br>    });<br>  });<br>  ...<br>})</pre><p>As a bonus, we put all alphabets and symbols to JSON files in a special folder — __fixtures__. Thus, we will reduce the test file size, and the developers who work with this function will concentrate only on the logic during some changes.</p><pre>import { validateName } from &#39;./validator.js&#39;;<br><br>import latinLetters from &#39;./__fixtures__/latin-letters.json&#39;;<br>import acceptedSymbols from &#39;./__fixtures__/accepted-symbols.json&#39;;<br>import notAcceptedSymbols from &#39;./__fixtures__/not-accepted-symbols.json&#39;;<br>import cyrilicLetters from &#39;./__fixtures__/cyrilic-letters.json&#39;;<br>import koreanLetters from &#39;./__fixtures__/korean-letters.json&#39;;<br><br>....</pre><p>By doing these manipulations, we managed to cover a lot of cases, our code has no duplicates, and we have good documentation for our function.</p><p>I hope you liked this article and found it helpful. It’s just a few examples of how we can improve our tests. But in the nearest future, we will look through more examples. And I hope more developers will understand the power of good tests.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=902599669fc8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[10 tips on how to prepare yourself for the first react project]]></title>
            <link>https://medium.com/@manguradima/10-tips-on-how-to-prepare-yourself-for-the-first-react-project-7b93a4786d3d?source=rss-1044e8315cf5------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b93a4786d3d</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[freshers]]></category>
            <category><![CDATA[junior-developer]]></category>
            <dc:creator><![CDATA[Dmytro Manhura ]]></dc:creator>
            <pubDate>Sat, 03 Dec 2022 13:48:48 GMT</pubDate>
            <atom:updated>2022-12-04T08:43:44.768Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sIy2j8qkJWShdNscnB8Zlw.png" /><figcaption>Kyiv at night</figcaption></figure><p>React is an excellent tool for writing organized, reusable, and well-performing code. You must prepare if you have a chance to work on a project where the react ecosystem is used. I want to share tips to help you nail your first react project and to be a valuable player in your development team</p><h3>1. React documentation</h3><p><a href="https://reactjs.org/docs/getting-started.html">React official documentation</a> is a good starting point. You may know some basics. But refreshing your knowledge is always appropriate. The official documentation is well organized and consists of many practical examples. You can solve almost every issue based on tips that the documentation provides. Read all sections step by step and pay attention to advanced guides.</p><h3>2. TODO list application</h3><p>From theory to practice. So that you don’t get bored, let’s start writing code. We will implement the standard TODO list application that will consist of the following functionality:</p><ul><li>list of todos</li><li>the ability to filter todos by title</li><li>the ability to switch between active and not active todos</li><li>the ability to add new todo</li><li>the ability to change todo’s status</li><li>the ability to delete todo;</li></ul><p>Please focus on business logic, not UI. In this step, business logic is more important than UI. It’s better to save time and get more familiar with React. I recommend using React Bootstrap or Material-UI for styling. These libraries provide various components which are easy to use, such as Inputs, Cards, Switcher, etc.</p><h3>3. Redux</h3><p>After the basic functionality has been implemented on pure react, we can add Redux to our application. Of course, there are hooks. But no one knows how long it will take to replace Redux in all existing projects. Probably, then there will be no more hooks.</p><p>So Redux is a library that provides a flux approach to managing data. This approach is based on a flow architecture that requires one source of true, actions, and reducers. You can find more detail in the <a href="https://redux.js.org/">official documentation</a>.</p><p>Let’s transfer the local state of components to the global store. Next, we have to add actions and reducers and connect react application to the store.</p><h3>4. Tests (Jest, Cypress)</h3><p>Tests are an essential part of every reliable application. Tests can help catch a lot of issues and prevent unexpected behavior. In addition to the fact that tests are necessary for themselves, they also help to structure the code and write compact functions that can do only one thing. As a result, your codebase will be easier to maintain, the development cycle will be reduced, and you will be able to implement more features in less time.</p><p>There are two types of tests that you might find helpful: integrations tests and unit tests. I recommend you to be familiar with both. Integration tests will help you cover user flow cases. You will be confident that every critical application part is working correctly. However, unit tests are more appropriate if you want to cover some business logic. To be clear, unit tests suites more for actions, reducers, and API calls. Integrations test for components and behaviors.</p><p>At this moment, Jest and Cypress are like standards in react ecosystem. Don’t be afraid to start familiarising yourself with both. The more you know about tests, the better developer you become.</p><h3>5. Pagination</h3><p>Gradually complicate the application by adding pagination. We do not focus on layout. Instead, you can use a ready-made component, such as bootstrap provides. For realistic use of pagination, a server with a database is needed, with the help of which it will be possible to receive, delete and update todos. You can use mine. Here is a <a href="https://github.com/dimamanhura/TO-DO-List-app-API">link</a> to the repository. It is also helpful to add the ability to switch between different numbers of todos on the page.</p><h3>6. Authorization</h3><p>The registration and authorization forms can be added in a modal window, but these forms can be routed to different application pages to cover more topics. To do this, connect the <a href="https://reactrouter.com/en/6.4.4/start/overview">Router</a>. So instead of one page, we have three (todos list, sign-in, and sign-up pages). You can also add validation for inputs. <a href="https://formik.org/">Formik</a> is an excellent library that makes it easy to work with forms. Another interesting task is to add authorization using Facebook or Instagram.</p><h3>7. Sockets</h3><p>Implementing sockets is an excellent way to understand how critical removing listeners are. The return function inside useEffect hook was implemented for cleanup. If you don’t unsubscribe from some listeners inside useEffect hook, the application will run into performance issues and unnecessary duplications.</p><h3>8. Localization</h3><p>Localization benefits businesses. Although English is a popular language, you should still take advantage of the opportunity to attract customers who do not know it. Adding localization does not require many resources. It will be helpful for you to gain experience with libraries that simplify the implementation of localization. i18next is a good solution for React apps.</p><h3>9. Performance</h3><p>Improving performance in react application is a challenging task for a fresher. However, in an application like ours, you can visually see how performance improvements affect user experience. For example, let’s add about 1000 todos to one page. Updating the state of one todo involves re-render all others. Re-render the DOM is the heaviest operation that eats a lot of CPU.</p><p>The mission of a good react developer is to write code that avoids re-renders as much as possible. There are a lot of techniques for improving react application performance. Some are present by default, such as <strong>PureComponemt</strong>, <strong>useMemo</strong>, and <strong>useCallback</strong>. But some are provided by 3rd part libraries. For example, <a href="https://react-window.vercel.app/#/examples/list/fixed-size">react-window</a> library was created for efficiently rendering large lists of items. React window works by only rendering <em>part</em> of a large data set.</p><h3>10. TypeScript</h3><p>Rewrite everything in TypeScript. TypeScript is gaining popularity and is one of the fastest-growing programming languages in terms of frequency of use in new projects. TypeScript extends the power of JavaScript, adds static typing, and it reduces the chance of error. Switching to TypeScript can speed up the development and debugging process. For a JavaScript developer, TypeScript is a required topic to learn.</p><p>I hope you liked this article and found it helpful. Of course, there are tips that a fresher also needs to go through to navigate the React ecosystem better and quickly integrate into the project. I highlighted the main topics and made the material as practical as possible.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b93a4786d3d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>