<?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"><channel><title><![CDATA[Anuradha Kumari's blog]]></title><description><![CDATA[Anuradha Kumari's blog]]></description><link>https://anu.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 12 Nov 2026 00:41:36 GMT</lastBuildDate><atom:link href="https://anu.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[2021 reflections and what's next in 2022]]></title><description><![CDATA[Hi everyone, today is the last day of year 2021 and I wanted to do a year end review and also share my plans for the next year with you all. Amidst all the…]]></description><link>https://anu.hashnode.dev/2021-reflections-and-whats-next-in-2022</link><guid isPermaLink="true">https://anu.hashnode.dev/2021-reflections-and-whats-next-in-2022</guid><category><![CDATA[life]]></category><dc:creator><![CDATA[Anuradha Kumari]]></dc:creator><pubDate>Fri, 31 Dec 2021 15:52:45 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1641570713515/n3_oXNx72n.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hi everyone, today is the last day of year 2021 and I wanted to do a year end review and also share my plans for the next year with you all.</p>
<h2 id="heading-2021-plans-and-goals">2021 plans and goals</h2>
<p>Amidst all the chaos of pandemic that 2020 brought upon us, I did not plan extensively for 2021 but instead I focused on a theme.</p>
<p><strong>I wanted the year of 2021 to be my year of YES.</strong></p>
<p>I decided to not hesitate when new opportunities come up and go for exploring new things in life.</p>
<p>There were three high-level things which I wrote to focus on 1st January 2021 in my journal, they were: </p>
<ol>
<li>Health</li>
<li>Career</li>
<li>Growth </li>
</ol>
<h2 id="heading-health">Health</h2>
<h3 id="heading-in-2021">In 2021</h3>
<p>I had multiple health issues and I wanted to focus on improving it. </p>
<p>What did I do about it? </p>
<p>I did meditation, walking and kept my diet in check for most of the days. And also took consultation from a Doctor whose medication turned out to be effective for me. </p>
<p>As of today my health conditions have improved by around 70% and it is a huge win for me. </p>
<h3 id="heading-for-2022">For 2022</h3>
<p>My first and most important goal again is to focus on my health. </p>
<p>Everything else is secondary.</p>
<h2 id="heading-career">Career</h2>
<h3 id="heading-in-2021">In 2021</h3>
<p>I wanted to take my career to next level and get a relocation job. </p>
<p>I started my job search in Jan 2021, accepted the job offer for my current company in April and then moved to Netherlands in end of September.</p>
<p>This was not an easy decision for me. </p>
<p>I was pretty anxious and scared, this was a huge step for my life and I was pushing myself way out of my comfort zone. </p>
<p>But today I can say proudly that I'm glad that I took this decision and did not step back due to the fear of unknown. </p>
<p>I just tried to <em>live by my theme of saying yes</em> to every opportunity that I felt could be a good step for me instead of doubting myself. </p>
<h3 id="heading-for-2022">For 2022</h3>
<p>I plan to take my career to even more heights by exploring new technologies and working towards being a better developer and developer advocate.</p>
<p>I specifically want to explore more and more about accessibility and continue sharing my learnings and spread more awareness about it in the tech community.</p>
<h2 id="heading-growth">Growth</h2>
<p>The third focus for me was on growth - in whatever I was already doing. </p>
<h3 id="heading-in-2021">In 2021</h3>
<p>I wanted to do more conferences and grow my technical expertise. </p>
<h4 id="heading-speaking-in-events">Speaking in events</h4>
<p>I aimed to participate in at least one event per month and I ended up speaking at 20 events in 2021. </p>
<p>Among these were two workshops for college students where I taught web development and React JS. </p>
<p>I also spoke at JS World conference which was attended by around 50,000 people and it is the biggest conference I have ever been part of till now. </p>
<p>I also got the chance to <a target="_blank" href="https://www.anuradhakumari.com/talks">speak at some amazing events</a> like Google I/O extended UK and Ireland event, at DevFest India, Next JS conference and React India conference. </p>
<h4 id="heading-mcing-at-conferences">MCing at conferences</h4>
<p>I also wanted to try hosting an event and I got an opportunity to <a target="_blank" href="https://twitter.com/miracle_404/status/1468908365250273283">MC at the GraphQL Galaxy conference</a> in December 2021. </p>
<h3 id="heading-for-2022">For 2022</h3>
<p>I absolutely loved being Master of Ceremonies and for 2022, I would like to MC for more events. </p>
<p>For speaking apsirations, in 2022, my goal is to deliver talks in few in-person conferences (of course only if the travelling is safe). </p>
<p>I would like to meet more people in tech in person and I also want to try giving a keynote talk at a conference.</p>
<h2 id="heading-wins-in-2021">Wins in 2021</h2>
<h3 id="heading-gde-and-mde">GDE and MDE</h3>
<p>Among my most favourite wins of 2021 is that I became a Google Developers Expert for Web technologies and also a Cloudinary Media Developer Expert. </p>
<p>These titles definitely boost my confidence and motivate me to contribute more and more towards helping the developer community. </p>
<h3 id="heading-started-youtube-channel">Started YouTube Channel</h3>
<p>And last but not the least, I wanted to start my YouTube channel but I procrastinated for almost 11 months out of 12 months in 2021 before actually starting <a target="_blank" href="https://www.youtube.com/channel/UCzv8q9-tSIQuTDzgB1BgXMQ">my YouTube channel</a> on 29 November 2021. </p>
<p>I have posted three videos on my channel till now and in 2022 my plan is to create a lot more content on YouTube channel.</p>
<h3 id="heading-reading-books">Reading books</h3>
<p>I also did a lot of reading in 2021. I started with a goal of reading 15 books and I ended up reading <a target="_blank" href="https://www.goodreads.com/review/list/105616872-anuradha-kumari?ref=nav_mybooks&amp;shelf=read">21 books in 2021</a>. </p>
<p>Now for 2022 I want to make a reading a daily habit, even if it's just for 30 minutes daily but I would like to start my day with reading a book. </p>
<p>And my goal for 2022 is reading at least 25 books. </p>
<h3 id="heading-journaling">Journaling</h3>
<p>In 2021, one of the best things I did was to <a target="_blank" href="https://twitter.com/miracle_404/status/1457316830477959178?s=20">journal daily</a>. </p>
<p>So I have my whole 2021 written out at a high level in my journal and due to this I was able to reflect throughout my days in the year.</p>
<p>I like to go back to it and re-read on the days I am feeling low and I try to remind myself that it's okay I'm doing good and that i do not need to push myself a lot. </p>
<p>I have prompts written in my journal to take rest, breathe and just pause for some time. </p>
<p>This was very effective for me, and I would continue this journaling habit in 2022 as well. </p>
<h3 id="heading-people-and-connections">People and connections</h3>
<p>I met some wonderful people from different parts of the world, and made new friends ❤️.</p>
<hr />
<p>So these were my reflections for year 2021 - on what were my goals and wins and also what I plan to do in 2022 on a very high level. </p>
<p>Now I would also like to take some moments to share what did not went well and what learnings I have to take from 2021 into the New Year 2022. </p>
<h2 id="heading-what-did-not-went-well-in-2021">What did not went well in 2021</h2>
<p>A few things which did not work for me were:</p>
<ul>
<li>despite not having a good health, I was still not able to meditate and exercise consistently and hence I had some really tough days both physically and mentally.</li>
<li>I wanted to write more technical blogs but I was not able to contribute much via the writing medium.</li>
<li>I had so many plans for my YouTube channel, but they are yet to be executed.</li>
<li>I struggled with the sudden drop in the temperature when I moved from India to Netherlands. It was pretty harsh encounter and I had a tough time adapting to the new climate. Also, some of the experiences would have gone smoother if I had planned better. But it's all good now.</li>
</ul>
<h3 id="heading-inconsistency">Inconsistency</h3>
<p>I see inconsistency in my habits and due to this I have seen some of my plans drop and also I have procrastinated and started something is very late.</p>
<h2 id="heading-what-are-my-learnings-takeaways-from-these">What are my learnings/ takeaways from these?</h2>
<p>I'm trying currently to meditate daily and go out for walks and runs at least three times a week because I want to be in good health.</p>
<p>I'm also trying to plan out my days and weeks so that I stay consistent and do not procrastinate on what I want to do.</p>
<h2 id="heading-theme-for-2022">Theme for 2022</h2>
<p>I would also like to share with you my theme for the year 2022. </p>
<p>And it will be the <strong>year of saying NO.</strong> </p>
<h3 id="heading-what-do-i-want-to-say-no-to">What do I want to say no to?</h3>
<ul>
<li><p>I want to say no to devaluing myself. I often play myself down, and my achievements, and it diminishes my confidence. I just don't want to do that anymore.</p>
</li>
<li><p>I also want to say no to the self-deprecating thoughts which always holds me back from doing something new.</p>
</li>
<li><p>I also want to say no to apologising for dreaming big and going all in on whatever I want to achieve.</p>
</li>
<li><p>I often feel that I am not doing good enough and in 2022, I want to say no to this feeling of not feeling competent enough.</p>
</li>
<li><p>And I want to say no to anything and everything that can have a negative impact on my physical and mental well being.</p>
</li>
</ul>
<h2 id="heading-towards-a-better-year">Towards a better year</h2>
<p>So, these were some of my reflections of the year that 2021 was and what goals I have in mind for the year 2022. </p>
<p>Do let me know in comments what are some of the goals and plans that you have made for year 2022. </p>
<p>I pray for the pandemic to end this year. <strong>Let’s welcome the new year with hope of good health, blessings and happiness for everyone.</strong></p>
<p>Happy New Year! Take care, stay safe and healthy!</p>
]]></content:encoded></item><item><title><![CDATA[Useful tips for JavaScript test automation]]></title><description><![CDATA[Testing is crucial for the success of any product or application. No user wants to use a broken product. Testing is the way to ensure that our product is…]]></description><link>https://anu.hashnode.dev/useful-tips-for-javascript-test-automation-e57b329899f4</link><guid isPermaLink="true">https://anu.hashnode.dev/useful-tips-for-javascript-test-automation-e57b329899f4</guid><category><![CDATA[Testing]]></category><category><![CDATA[automation]]></category><dc:creator><![CDATA[Anuradha Kumari]]></dc:creator><pubDate>Mon, 07 Jun 2021 09:24:49 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1623059095946/77hMigt-2G.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Testing is crucial for the success of any product or application. No user wants to use a broken product. Testing is the way to ensure that our product is working properly. Predominantly, there are two ways of testing — manual testing and automated testing.</p>
<p>Today we are going to explore automation testing in JavaScript. We will learn some useful tips which will help create robust automated testing regimens for a JavaScript application.</p>
<h2 id="what-is-test-automation">What is test automation?</h2>
<p><a target="_blank" href="https://www.perfecto.io/blog/what-is-test-automation">Test automation</a> is a software testing mechanism that uses other software, tools, and scripts to run predefined test cases. It reduces manual effort by automating the testing process and hence provides much more coverage in less time. There are many different types of tests that can be automated, like — unit testing, regression testing, smoke testing, integration testing, etc.</p>
<h2 id="tips-for-javascript-test-automation">Tips for JavaScript test automation</h2>
<h3 id="1-choose-the-right-tool">1. Choose the right tool</h3>
<p>There are various automation tools available in the market, and hence choosing the best for our application is a crucial task. JavaScript is one of the most popular programming languages. And hence, there are many automation tools available for testing JavaScript websites and applications.</p>
<p>Some of the most commonly used JavaScript testing frameworks are <a target="_blank" href="https://webdriver.io/">WebdriverIO</a>, <a target="_blank" href="https://www.cypress.io/">Cypress</a>, <a target="_blank" href="https://www.selenium.dev/">Selenium</a>, etc.</p>
<p>To choose a JavaScript automated testing framework, some of the important things to consider are:</p>
<ul>
<li><p>What will be the cost to develop and maintain the scripts?</p>
</li>
<li><p>Which platform supports are needed, like web, mobile, etc? Does it also need to support cross-browser testing?</p>
</li>
<li><p>Can the tool be integrated with our CI/CD process?</p>
</li>
</ul>
<h3 id="2-plan-and-decide-the-test-cases-to-automate">2. Plan and decide the test cases to automate</h3>
<p><img src="https://cdn-images-1.medium.com/max/3000/0*8RDyLCqzgCnzuuFO" alt="[Source](https://cdn.hashnode.com/res/hashnode/image/upload/v1623059092720/dHBOm7de2.html)" /><em><a target="_blank" href="https://www.katalon.com/resources-center/blog/choose-automation-test-cases/">Source</a></em></p>
<p>Before we start automating, we need to define the scope of automation. Certain criteria can help us decide which test cases need to be automated.</p>
<ul>
<li><p>Common and frequently used scenarios should be automated as much as possible.</p>
</li>
<li><p>Core business logic should be tested via automation.</p>
</li>
<li><p>Automation should include different paths of a use case. For example- When the user tries to check out the cart, what could happen? If a user is logged in, they should be navigated to the checkout view. But if the user is not logged in, they should be navigated to the login/signup page.</p>
</li>
<li><p>Use good test data to create automation tests</p>
</li>
<li><p>Avoid automating unstable functionality</p>
</li>
</ul>
<h3 id="3-write-meaningful-names-for-test-cases">3. Write meaningful names for test cases</h3>
<p>Proper naming is a basic but essential part of writing robust test cases. Creating meaningful and self-explanatory names for test cases helps developers, testers as well as other team members.</p>
<p><strong>For example:</strong> Clicking the checkout button should navigate to the login/signup page if the user is not logged in.</p>
<p>A proper test case name could explain:</p>
<ul>
<li><p>What are we testing? — what will happen when the user clicks on the checkout button</p>
</li>
<li><p>What are the conditions used for that testing? — The user is not currently logged in.</p>
</li>
<li><p>What is the expected result of the test? — The user is navigated to the login/signup page</p>
</li>
</ul>
<h3 id="4-measure-test-coverage">4. Measure test coverage</h3>
<p>Test coverage measures the amount of code or functionality that is covered by the test cases. While numbers are not proof of the quality of testing, measuring test coverage is essential. There are multiple tools for test coverage, like <a target="_blank" href="https://istanbul.js.org/">Istanbul</a>. Istanbul provides support for the most popular JavaScript testing frameworks and is widely used.</p>
<p>We can also integrate the coverage reports with our continuous integration system to track and manage the test coverage.</p>
<h3 id="5-provide-logical-data-inputs-to-the-test-case">5. Provide logical data inputs to the test case</h3>
<p>Using realistic inputs helps improve the accuracy of the test case. If we use dummy data that is in no way close to the data from real-life, the test case might not evaluate the actual output and hence will not be very effective in catching potential issues.</p>
<p>For example:</p>
<ul>
<li><p>If we test a text area for an address, we need to test it with different possible values for a valid address.</p>
</li>
<li><p>If we have a minimum character validation, of 7 characters, for example. Then if the user adds 7 spaces, it should not be accepted as valid.</p>
</li>
</ul>
<p>Real-world scenarios can be unexpected, and the application might not always be used in a pre-defined way. So using test data as close to real-world data as possible would make the tests more robust and failure-proof.</p>
<h3 id="6-choose-the-right-selectors">6. Choose the right selectors</h3>
<p>This is specifically for user interface (UI) automated test cases. While testing the UI, it is imperative to use the right selectors for the elements in DOM. It helps to ensure that the automated tests are picking the right elements to perform the action on and reduces the false errors. I must also point out that the order of selectors is important, and it also helps locate the correct element faster.</p>
<p>For example: Using data-testid for the HTML elements. It will remain unchanged even if we change the original class/id of that element.</p>
<h3 id="7-write-small-and-independent-test-cases">7. Write small and independent test cases</h3>
<p>Each test case should target one specific use case which will help make them smaller and faster. Also, if we create multiple small and independent test cases, we can run them parallel, and receive the test results faster. Faster feedback also leads to faster detection of any issue and faster shipping of a better quality product.</p>
<h2 id="conclusion">Conclusion</h2>
<p><img src="https://cdn-images-1.medium.com/max/2708/0*wXJ7rwh8vd5LnBk_" alt="[Source](https://cdn.hashnode.com/res/hashnode/image/upload/v1623059094259/VjaB5q991.html)" /><em><a target="_blank" href="https://medium.com/javarevisited/my-top-5-lessons-on-test-automation-ad4dec93ae2f">Source</a></em></p>
<p>Test automation reduces human efforts for doing repetitive or complex work, making it cost and time-effective in the long run. Before automating the tests, we need to decide the budget, tools, use cases to automate, the feasibility of automating them, and the efforts and skill set required. There are several open-source tools available on the internet and we can use them to create efficient and powerful automation tests that will ensure the end product/application’s quality.</p>
<p>Happy testing!!</p>
]]></content:encoded></item><item><title><![CDATA[Accessibility — The Ethical Responsibility]]></title><description><![CDATA[Hi everyone, how are you? If you are able to read this article without having to use any assistive technologies, you should be thankful for that privilege…]]></description><link>https://anu.hashnode.dev/accessibility-the-ethical-responsibility</link><guid isPermaLink="true">https://anu.hashnode.dev/accessibility-the-ethical-responsibility</guid><category><![CDATA[a11y]]></category><category><![CDATA[Accessibility]]></category><dc:creator><![CDATA[Anuradha Kumari]]></dc:creator><pubDate>Mon, 21 Dec 2020 06:18:53 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1608531303811/1fyj4Z-pl.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="and-the-morally-right-thing-to-practice">and the morally right thing to practice</h2>
<p>Hi everyone, how are you? If you are able to read this article without having to use any assistive technologies, you should be thankful for that privilege. If you are using assistive technologies and are able to access this article without any issues, that’s your right and it should never be the other way.</p>
<p>You might or might not have heard about accessibility. Even if you would have heard about it, there might be chances you encountered some of the myths surrounding it which makes it burdensome or complex in general.</p>
<p>Today, we are going to start from the very basics of the topic, at 101 level, and gradually move towards more details. This article is specifically dedicated to introducing accessibility in general and how does it span to the web.</p>
<p>Accessibility also has a numeronym — <strong>a11y (</strong>where <strong>11</strong> stands for the number of letters between ‘a’ and ‘y’<strong>)</strong>, and we will use both accessibility and a11y interchangeably in the rest of the article</p>
<p>Ok, get set go!!</p>
<h2 id="introduction">Introduction</h2>
<p>Accessibility is about making things and services accessible to all people (regardless of their ability or disability).</p>
<p>Let’s understand through some real-world scenarios:</p>
<h3 id="scenario-1-a-wheelchair-user-needs-to-shop-for-groceries">Scenario 1: A wheelchair user needs to shop for groceries</h3>
<p>But, staircases are the only way to enter the supermarket.</p>
<img alt="staircases to a building" src="https://miro.medium.com/max/2046/0*DU_G4F-v-ZJu9tfF.jpg" />

<p>Image Credits: <a target="_blank" href="https://st2.depositphotos.com/1177973/11747/i/950/depositphotos_117471804-stock-photo-modern-staircases-on-street.jpg">depositphotos</a></p>
<p>So, how will the customer shop for groceries? By not thinking about the different customer requirements, that supermarket made shopping a bad experience for some of the users. Also, What do you think are the odds of that customer visiting this shop again?</p>
<p>Negligible, right?</p>
<p>This is one of the very basic examples of how ignoring accessibility is bad for both — users as well as the business.</p>
<p><strong>What could have been the right way:</strong> Providing ramps and elevators in addition to the staircases. This way users with different types of mobility requirements can shop without any hurdles.</p>
<blockquote>
<p>Happy users == successful business</p>
</blockquote>
<h1 id="what-this-has-to-do-with-the-web">What this has to do with the web?</h1>
<p>In the words of <em>Tim Berners-Lee, W3C Director and inventor of the World Wide Web:</em></p>
<blockquote>
<p>The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.</p>
</blockquote>
<p>The web was created to be accessible by default, to all users. Accessibility is an inherent aspect of the web.</p>
<p>Ok, so why are we talking about accessibility right now.</p>
<p>Because, we are making the web inaccessible through bad decisions, bad design, bad coding practices, and bad testing.</p>
<p>We create websites and applications so that they can be used by people. But, if users will not able to use these, why are we even creating these services and resources??</p>
<h2 id="but-really-do-we-need-to-consider-accessibility">But really, do we need to consider accessibility?</h2>
<p>I am glad you asked.</p>
<p>The short answer is <strong>yes.</strong></p>
<p>There are many times where we see the business or decision-makers shrugging off the accessibility features as an afterthought.</p>
<p>Does any of the below arguments/excuses ring a bell:</p>
<ol>
<li>We do not have lots of users who might need it.</li>
<li>Accessibility is expensive, we do not have the budget/resources for that.</li>
<li>Well, it’s going to be time-consuming, we are running on a tight schedule.</li>
<li>We can always add it later if we need it.</li>
<li>It doesn't matter.</li>
</ol>
<blockquote>
<p>These show at best a <strong>lack of awareness</strong> and at worst <strong>lack of empathy and consideration for diverse users.</strong></p>
</blockquote>
<p>If you have ever come across such conversations, I suggest to go and read <a target="_blank" href="https://www.maxwellantonucci.com/">Max Antonucci</a>’s article on <a target="_blank" href="https://www.maxwellantonucci.com/posts/2019/05/01/comebacks-anti-accessibility-arguments/">comebacks for five wrong accessibility arguments</a>.</p>
<p>To understand why we need web accessibility, we need to understand our users and their needs, their abilities, and the tools/techniques they use to access the web.</p>
<p>As per <a target="_blank" href="https://www.who.int/health-topics/disability#tab=tab_1">WHO (World Health Organization)</a>,</p>
<blockquote>
<p>Around <strong>15%</strong> of the global population — over a billion people — lives with some form of disability, of whom 2–4% experience significant difficulties in functioning.</p>
</blockquote>
<img alt="Silhoutte of different persons with disabilities" src="https://miro.medium.com/max/1538/0*4fTElJtYpdFwwVLr" />

<p>There are different types of disabilities, including but not limited to:</p>
<ul>
<li>Visual</li>
<li>Auditory</li>
<li>Physical</li>
<li>Cognitive</li>
<li>Neurological</li>
</ul>
<p>Disabilities can be divided into 4 categories. Let’s look at those using the example of users suffering from different kinds of vision impairment.</p>
<ul>
<li><strong>Permanent</strong> — Some users could have permanent blindness, while others could have a varying range of low sightedness.</li>
<li><strong>Temporary</strong> — issues like an eye infection or eye surgery could temporarily impair the users visually.</li>
<li><strong>Situational</strong> — trying to read something in a bright environment,</li>
<li><strong>Progressive</strong> — eyesight could start decreasing as age increases. So a person who has sharp eyesight today, might not have the same sharpness tomorrow.</li>
</ul>
<h2 id="a11y-is-more-than-disabilities">A11y is more than disabilities.</h2>
<p>It also helps users who might be facing:</p>
<ul>
<li><strong>technical</strong> challenges — using the content on smaller devices, slower internet connection, older browsers, etc.</li>
<li><strong>Situational</strong> challenges — trying to listen to audio in a loud place, trying to watch videos in non-native languages or languages which we do not understand, etc.</li>
</ul>
<h2 id="how-do-these-users-use-the-internet">How do these users use the internet?</h2>
<p>They use <a target="_blank" href="https://en.wikipedia.org/wiki/Assistive_technology">assistive technologies</a>, like screen readers, screen magnification, speech recognition, refreshable braille display, large print tactical keyboards, and many more.</p>
<blockquote>
<p>But the effectiveness of these tools depends on how the actual content has been created.</p>
</blockquote>
<p>And hence these assistive technologies and devices could only be useful if the website or application has been designed and developed in a way that is understandable by them.</p>
<h2 id="accessibility-benefits-everyone">Accessibility benefits everyone</h2>
<p>Some widely used a11y features which help everyone regardless of disability are:</p>
<ol>
<li>The subtitles for any video like movies, series, or any tutorial,</li>
<li>Transcripts for audio, like — podcasts</li>
<li>Dark mode toggle on the websites or applications.</li>
</ol>
<h1 id="how-do-we-start">How do we start?</h1>
<p>Now that we know that web accessibility is important and we must all work towards creating accessible content, the next question would be how do we do that, how to start working with an accessibility perspective?</p>
<p>Few suggestions for that:</p>
<ul>
<li><strong>Be aware:</strong>
The first step towards fixing any issue is the acknowledgment of that issue. Unless we understand and acknowledge that web inaccessibility is a critical issue, we can’t go ahead and make it a priority.
So, make yourself aware.</li>
<li><strong>Read about accessibility:</strong> Explore the various contents, documentation, tutorials, blogs, etc. present on the internet. I have added a few links for resources that can be used to get started.</li>
<li>Start thinking and implementing from the <strong>user perspective.</strong></li>
</ul>
<h2 id="make-informed-decisions">Make informed decisions</h2>
<h3 id="as-you-go-on-designing-implementing-and-testing-the-product">as you go on designing, implementing, and testing the product.</h3>
<ul>
<li>Choosing color schemes, will it be accessible?</li>
<li>Is the color contrast good enough for the content to be read by users with vision impairment?</li>
<li>Is that pie-chart understandable by people with color blindness?</li>
<li>What if the user cannot see? Will this image still make sense to them? Have I provided extra information (alternative description) that can be used by the user to understand what we are trying to convey using that image?</li>
<li>Is this call to action element clickable by keyboard?</li>
<li>Will users be able to navigate this modal popup?… and so on.</li>
</ul>
<h2 id="who-should-be-responsible-for-ensuring-accessibility">Who should be responsible for ensuring accessibility?</h2>
<p>This is another burning question in the business model, where people often put off the responsibilities of making the product accessible to either developers or designers.</p>
<p>But that’s not the case. Let’s try to figure who all should be responsible for the accessibility of the product:</p>
<ul>
<li>Business owners</li>
<li>Product owners</li>
<li>Project managers</li>
<li>Designers</li>
<li>Team leads</li>
<li>Developers</li>
<li>Testers</li>
<li>SEO specialists</li>
<li>Marketing personals</li>
<li>Content creators</li>
</ul>
<p>In a nutshell,</p>
<blockquote>
<p>Pretty much everyone on the team is responsible for ensuring the accessibility of the product.</p>
</blockquote>
<h2 id="resources-to-refer-to">Resources to refer to</h2>
<ul>
<li><a target="_blank" href="https://www.w3.org/WAI/standards-guidelines/wcag/">The official website of WCAG (Web Content Accessibility Guidelines)</a></li>
<li><a target="_blank" href="https://www.w3.org/standards/webdesign/accessibility">W3 accessibility documentation</a></li>
<li><a target="_blank" href="https://webaim.org/standards/wcag/checklist">WebAIM checklist for web accessibility</a></li>
<li><a target="_blank" href="https://developers.google.com/web/fundamentals/accessibility/">Google Developers group accessibility fundamentals</a></li>
<li><a target="_blank" href="https://www.a11yproject.com/">The a11y project</a></li>
</ul>
<p>Also, I have created a website <a target="_blank" href="https://explore-a11y.netlify.app/">Explore A11y</a> that lists accessibility examples and resources for easy reference. You can check it out for details.</p>
<p><span class="me fj go mf mg mh"></span><span class="me fj go mf mg mh"></span><span class="me fj go mf mg"></span></p>
<h2 id="conclusion">Conclusion</h2>
<p>Accessibility is the responsibility of each one of us, together we can make the web a lot more accessible.</p>
<blockquote>
<p>We need to focus on a11y just like everything else because it is the right thing to do.</p>
</blockquote>
<p><span class="me fj go mf mg mh"></span><span class="me fj go mf mg mh"></span><span class="me fj go mf mg"></span></p>
<p>If you liked this article, please share it on social platforms. Also, you can connect with me on <a target="_blank" href="https://twitter.com/miracle_404">twitter</a> or <a target="_blank" href="https://www.linkedin.com/in/anuradha15/">linkedin</a> if you would like to discuss or provide any feedback/suggestions.</p>
<p>Stay tuned, meet you in the next article! Take care!</p>
]]></content:encoded></item><item><title><![CDATA[Configuring prettier and eslint plugins for React from scratch]]></title><description><![CDATA[Hi everyone, how are you? Today we are going to configure the prettier and eslint plugins for a React project from scratch. We will be using VSCode as the…]]></description><link>https://anu.hashnode.dev/configuring-prettier-and-eslint-plugins-for-react-from-scratch</link><guid isPermaLink="true">https://anu.hashnode.dev/configuring-prettier-and-eslint-plugins-for-react-from-scratch</guid><category><![CDATA[Prettier]]></category><category><![CDATA[eslint]]></category><category><![CDATA[React]]></category><dc:creator><![CDATA[Anuradha Kumari]]></dc:creator><pubDate>Sun, 15 Nov 2020 12:01:20 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1605441745107/vXO6Hytqv.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[      
        <p>
          Hi everyone, how are you? Today we are going to configure the prettier and eslint plugins for a React project from scratch.
        </p>
        <p>
          We will be using
          <a href="https://code.visualstudio.com/">VSCode</a>
          as the default IDE, and all of the extension links in below section
          will point to VSCode extensions. If you are using any other IDE, you
          can find respective extensions on internet.
        </p>
        <p>
          Let's got through the steps one by one in the same order as below. Or,
          if you would like to check the final version of what we are going to discuss in below section, 
          <a href="https://github.com/anuk79/prettier-eslint-configuration-for-react">go to the GitHub repo with complete settings.</a>
        </p>
        
          <h2>Steps:</h2>
          <ol>
            <li>
              Create an empty folder named <strong>react-setup</strong> (or
              anything that you would like).
            </li>
            <li>
              Run below command to initialize a npm project: 
             <pre>npm init -y</pre>
It will create
              a <strong>package.json</strong> file with basic settings for us to
              get started with. You can always go ahead and update details in
              it, as per requirements.
            </li>
            <li>
              Since we are going to create a 
              <a href="https://reactjs.org/">react</a> 
              project, let's install React and ReactDOM dependencies by running
              below command:
              <pre>npm install react react-dom</pre>
            </li>
            <li>
              It's time now to add some code. Create a <strong>src</strong> 
              directory inside the project, add few files with code as below:
              <ul>
                <li>
                  index.html
                  <pre>
 <code>&lt;!DOCTYPE HTML&gt;
 &lt;html lang="en"&gt;
  &lt;head&gt;
    &lt;meta charset="UTF-8" /&gt;
    &lt;meta 
        name="viewport" 
        content="width=device-width, initial-scale=1.0" /&gt;
    &lt;title&gt;React prj setup&lt;/title&gt;
    &lt;link rel="stylesheet" href="./style.css" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id="root"&gt;
        The content was not rendered.
    &lt;/div&gt;
    &lt;script src="./app.js"&gt;&lt;/script&gt;
  &lt;/body&gt;
&lt;/html&gt;</code>
                  </pre>
                </li>
                <li>
                  app.js
                  <pre><code>import React from "react";
import { render } from "react-dom";

const App = () =&gt; {
  return (
    &lt;main&gt;
      &lt;h1&gt;Welcome&lt;/h1&gt;
      &lt;p&gt;
        Let's practice configuration of 
        prettier and eslint plugins for 
        a React application from scratch.
      &lt;/p&gt;
    &lt;/main&gt;
  );
};

render(&lt;App /&gt;, document.getElementById("root"));</code> </pre>
                </li>
                <li>
                  style.css
                  <pre><code>html {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  padding: 50px;
  background: 
  linear-gradient(
    45deg, 
    #d6c7ec 0%, 
    #f6d18d, 
    #eba2c4 100%);
  line-height: 1.5;
}

main {
  font-size: 1.2em;
  border-radius: 5px;
  padding: 20px;
  background-color: white;
}

h1 {
  font-variant: small-caps;
  font-size: 2.2em;
}</code>
                  </pre>
                </li>
              </ul>
            </li>
            <li>
              Install 
              <a href="https://parceljs.org/getting_started.html"> parcel</a>
              bundler to build the project and enable running it locally 
              <pre>
<code>npm i -D parcel-bundler</code></pre>
              You can use webpack as well for it, its configuration is out of
              scope for this article.
            </li>
            <li>
              Add a <strong>dev</strong> script in package json for starting the
              local dev server:
              <pre><code>"scripts": {
  "dev": "parcel src/index.html"
}</code>              </pre>
              Note: point it to the path of your index.html file. For my case, I
              have added it to src directory, and hence that path. If you have
              it in your public directory, you need to add it as 
              <strong>parcel public/index.html</strong>
            </li>
            <li>
              Now let's execute the dev command in the terminal: 
              <pre>npm run start</pre>
              You will see local server running at url 
              <a href="http://localhost:1234">http://localhost:1234</a>. Go to
              this url in browser and you should see the content getting
              rendered.
            </li>
            <li>
              Next, let's install 
              <a href="https://github.com/prettier/prettier"> prettier</a>
              by running the below command:
              <pre>npm install -D prettier</pre>
              Here, we have used -D because we want to install prettier only as
              a dev dependency, and it is not required for the production version of
              our application.
            </li>
            <li>
              After successful installation, we will see the entry for prettier
              being added to our package.json automatically:
              <pre><code>"devDependencies": {
  "parcel-bundler": "^1.12.4",
  "prettier": "^2.1.2"
}</code></pre>
            </li>
            <li>
              We need to add the script to format the files by running the
              prettier. For this, let's add a <strong>format</strong> script in package.json
              <pre><code>"format": "prettier \"src/**/*.{js,html,css}\" --write"</code></pre>
              Here, we are saying that run prettier on the files with extensions
              js, html or css.
              <br />
              <strong>--write</strong> flag is used to actually write the
              formatted code into the respective file. Otherwise, when we run format, it will just output the formatted version of our file.
              <br />
              Go ahead and execute the format command to check if your file got
              formatted:
              <pre>npm run format</pre>
            </li>
            <li>
              By default, the files will get formatted when we run the format command on it. But what if the files could get formatted when we save the file, without needing to run the command again and again.
              Cool, right?
              <br />
              Well, we can achieve that through our IDE settings. For VSCode,
              follow below steps to enable <strong>format on save</strong>:
              <ul>
                <li>
                  <a href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode">Install prettier extension</a>
                </li>
                <li>
                  <a href="https://supunkavinda.blog/vscode-editing-settings-json">
Open vscode settings</a>. 
                  Search for the "save on format" option and check it.
                </li>
                <li>
                  search for "require config to format" and check it as well.
                  This will format on save only if the prettier config is present
                  for the current project, and this way we do not force our
                  settings on all other projects which might not need the
                  prettier.
                </li>
                <li>
                  Add the prettier config file by creating a file named 
                  <strong>.prettierrc</strong> and add an empty object inside it
                  for now, which suggests that we are going to use all the
                  default configurations of prettier. So, our .prettierrc file
                  is going to look like below:
                  <pre><code>{ }</code></pre>
                </li>
                <li>
                  Now try to edit something in your app.js file and hit save.
                  You will notice the file gets formatted automatically. That's
                  amazing isn't it.
                </li>
              </ul>
            </li>
            <li>
              Next, we are going to add 
              <a href="https://eslint.org/">eslint</a>. Let's
              start by adding the eslint plugin for prettier by executing the
              below command:
              <pre><code>npm install -D eslint eslint-config-prettier</code></pre>
              After successful installation, you will notice these dependencies
              get added to devDependencies dection in package.json
              <pre><code>"devDependencies": {
  "eslint": "^7.13.0",
  "eslint-config-prettier": "^6.15.0",
  "parcel-bundler": "^1.12.4",
  "prettier": "^2.1.2"
}</code></pre>
            </li>
            <li>
              Lets explore the 
              <a href="https://prettier.io/docs/en/comparison.html">difference between prettier and eslint</a> 
              before moving ahead with configuring eslint.
              <ul>
                <li>
                  prettier: It is a code formatter. It deals with style issues
                  like indentation, keyword spacing, missing semicolons, comma
                  style, etc.
                </li>
                <li>
                  eslint: It concerns with the code quality rules like unused
                  variables, incorrect variable name, etc. Eslint can catch bugs
                  in code.
                </li>
                <li>
                  prettier and eslint complement each other, but there are some style rule conflicts between the two. This is why we have
                  installed <strong>eslint-config-prettier</strong>. It helps in disabling all eslint's conflicting rules automatically.
                </li>
              </ul>
            </li>
            <li>
              Let's add a file named <strong>.eslintrc</strong> for configuring
              the eslint for our project:
              <pre>
<code>{
  "extends": [
    "eslint:recommended", 
    "prettier", 
    "prettier/react"
  ], 
  "plugins": [],
  "parserOptions": {
    "ecmaVersion": 2018,
    "sourceType": "module",
    "ecmaFeatures": {
        "jsx": true
    }
  },
  "env": {
    "es6": true,
    "browser": true,
    "node": true
  }
}</code>
              </pre>
            </li>
            <li>
              Now, let's add the <strong>lint</strong> script in package json:
              <pre><code>"lint": "eslint \"src/**/*.{js,jsx}\" --quiet"</code></pre>
              We use the <strong>quiet</strong> flag to ignore the warnings of
              eslint, otherwise it might become too noisy.
            </li>
            <li>
              Let's also add the 
              <a href="https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint">eslint extension 
              for VSCode</a>. If you are using any other IDE, you can check extension for it too.
            </li>
            <li>
              Now, we need to add the React specific eslint plugins. For that,
              we run below command in terminal:
              <pre><code>npm install -D babel-eslint eslint-plugin-react 
eslint-plugin-react-hooks eslint-plugin-jsx-a11y 
eslint-plugin-import</code></pre>
              Let's break it up and see what each of these do:
              <ul>
                <li>
                  <strong>
                    <a href="https://github.com/babel/babel-eslint">babel-eslint</a>
                  </strong>
                  : As per its github :
                  <blockquote>
                    ESLint's default parser and core rules only support the
                    latest final ECMAScript standard and do not support
                    experimental (such as new features) and non-standard (such
                    as Flow or TypeScript types) syntax provided by Babel. 
                  </blockquote>
                  <em>
                    babel-eslint is a parser that allows ESLint to run on source
                    code that is transformed by Babel.
                  </em>
                </li>
                <li>
                  <strong>
                    <a href="https://www.npmjs.com/package/eslint-plugin-import">eslint-plugin-import</a>
                  </strong>
                  : Quoting the npm website for it:
                  <blockquote>

                    This plugin intends to support the linting of ES2015+ (ES6+)
                    import/export syntax, and prevent issues with the misspelling of
                    file paths and import names. All the goodness that the
                    ES2015+ static module syntax intends to provide, marked up
                    in your editor.
                  </blockquote>
                  You can explore the 
                  <a href="https://github.com/benmosher/eslint-plugin-import">github repo for the elsint-plugin-import</a> 
                  to gain more insights.
                </li>
                <li>
                  <strong>
                    <a href="https://www.npmjs.com/package/eslint-plugin-react">eslint-plugin-react</a>
                  </strong>
                  : It contains React specific linting rules for ESLint. You can
                  check the documentation for detailed rule information.
                </li>
                <li>
                  <strong>
                    <a href="https://www.npmjs.com/package/eslint-plugin-react-hooks">eslint-plugin-react-hooks</a>
                  </strong>
                  : As name suggests, it enforces the rules of React hooks. We
                  need to add it only if we are using React hooks (which most of
                  us might already be doing). Feel free to skip adding this
                  plugin of you are by any chance not using React hooks in your
                  project.
                </li>
                <li>
                  <strong>
                    <a href="https://www.npmjs.com/package/eslint-plugin-jsx-a11y">eslint-plugin-jsx-a11y</a>
                  </strong>
                  : It is a static AST checker for accessibility rules on JSX
                  elements. It supports many accessibility rules and it's one of
                  the <em>must have plugin for React</em> in my opinion. Explore
                  the 
                  <a href="https://github.com/jsx-eslint/eslint-plugin-jsx-a11y">github documentation of plugin</a> 
                  to learn more about the rules supported by this plugin.
                </li>
              </ul>
            </li>
            <li>
              After adding the plugins, it's time now to update the 
              <em>.eslintrc</em> config file:
              <pre>
<code>{
  "extends": [
    "eslint:recommended", 
    "plugin:import/errors",
    "plugin:react/recommended",
    "plugin:jsx-a11y/recommended",
    "prettier",
    "prettier/react"
  ], 
  "rules": {
    "react/prop-types": 0,
    "no-console": 1,
    "react-hooks/rules-of-hooks": 2,
    "react-hooks/exhaustive-reps": 1  
  },
  "plugins": [
    "import", 
    "react", 
    "jsx-a11y", 
    "react-hooks"
  ],
  "parserOptions": {
    "ecmaVersion": 2018,
    "sourceType": "module",
    "ecmaFeatures": {
        "jsx": true
    }
  },
  "env": {
    "es6": true,
    "browser": true,
    "node": true,
    "commonjs": true
  },
  "settings": {
    "react": {
        "version": "detect"
    }
  }
}</code></pre>
            </li>
            <li>
              Now, you should start seeing lint errors or warnings as you code
              further.
            </li>
          </ol>
        
        <p>
          Congratulations, you have successfully configured the basic prettier
          and eslint plugins for a React project. You can go ahead and add more
          rules as per specific project requirements. The npm website or GitHub
          repository of respective plugins would be the best place to explore
          the rules.
        </p>
      
      
        Credits: inspired from the learnings from
        the 
        <a href="https://frontendmasters.com/courses/complete-react-v5/">Complete React v5 course by Brian Holt</a> 
        on frontend masters.
        <p>
          If you found this useful, or have any suggestions, let me know in the comments. Also feel free to reach
          out to me on 
          <a href="https://twitter.com/miracle_404"> twitter</a>
          or 
          <a href="https://www.linkedin.com/in/anuradha15/">linkedin</a>.
        </p>
        <p>
          Wish you happy learning, keep on shining. Always remember, you are the
          best <span>🙌</span>
        </p>
      
]]></content:encoded></item><item><title><![CDATA[Why should I unit test my code?]]></title><description><![CDATA[Hi everyone, today we are going to explore the WHY question on unit testing the code. A very popular debate which I have observed in the developers’ world…]]></description><link>https://anu.hashnode.dev/why-should-i-unit-test-my-code</link><guid isPermaLink="true">https://anu.hashnode.dev/why-should-i-unit-test-my-code</guid><category><![CDATA[unit testing]]></category><category><![CDATA[TDD (Test-driven development)]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Jest]]></category><dc:creator><![CDATA[Anuradha Kumari]]></dc:creator><pubDate>Sat, 19 Sep 2020 13:40:05 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1600522787709/FXHnKIPGM.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hi everyone, today we are going to explore the WHY question on unit testing the code.</p>
<p>A very popular debate which I have observed in the developers’ world is <em>whether or not to write unit test cases for code and how writing those test cases could (no, it shouldn’t) be an overhead for the developers.</em></p>
<p>In my experience of almost 7 years of coding(mostly web development), I have met very few people who willingly unit test almost everything they code. So I feel that it’s the need of the hour to talk more about it and focus more on <a target="_blank" href="https://en.wikipedia.org/wiki/Test-driven_development">TDD (Test Driven Development)</a>.</p>
<p><img src="https://www.guru99.com/images/unit_testing_best_practise.png" alt="The more code you write without testing, the more paths you have to check for errors" /></p>
<p>As quoted by one of the articles <a target="_blank" href="https://smartbear.com/blog/test-and-monitor/a-short-lecture-on-the-value-and-practice-of-unit/">here</a>,</p>
<blockquote>
<p> unit tests are so important that they should be a first-class language construct.</p>
</blockquote>
<p>Me: Yes, please.. it’s about time now!!</p>
<hr />
<h3 id="what-is-unit-testing">What is unit testing?</h3>
<p>So, before you shall ask me, why should I unit test my code, 🤔
let’s start by understanding what exactly is unit testing…</p>
<p>There are many good explanations and introductory articles present on the web which cover this topic. </p>
<p>As <a target="_blank" href="https://en.wikipedia.org/wiki/Unit_testing">Wikipedia</a> says:</p>
<blockquote>
<p><strong>Unit testing</strong> is a <a target="_blank" href="https://en.wikipedia.org/wiki/Software_testing">software testing</a> method by which individual units of <a target="_blank" href="https://en.wikipedia.org/wiki/Source_code">source code</a>, sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures, are tested to determine whether they are fit for use.</p>
</blockquote>
<p>Here, the <strong>unit</strong> can be the smallest part of the application/module that can be tested in isolation. It can be a class in object-oriented programming, a function in procedural programming, a component in React, Angular, Vue, and so on.</p>
<p>The main purpose is to verify if that unit of code is working fine for all the scenarios which might occur. If yes, then whichever module consumes it, we are sure that this code will not break.</p>
<p>Unit testing makes the process <strong>more <a target="_blank" href="https://en.wikipedia.org/wiki/Agile_software_development">agile</a></strong>.
Ask me how?</p>
<p>This is because as the application evolves we need to add more and more features, and some times it involves revisiting earlier designs and code.</p>
<p><em>Unit tests can detect breaking changes in design contracts, and issues can be found very early and resolved.</em></p>
<p>They also help in <strong>safer refactoring</strong> of the code. If we are refactoring code, the end purpose of that code should remain the same, and if we have proper unit tests in place, any defect in refactored code can be easily detected by the test cases. </p>
<p>So we know where to debug if any of the test cases fail. This also makes the <a target="_blank" href="https://en.wikipedia.org/wiki/Debugging">debugging</a> process easier.</p>
<p>We have plenty of reasons to unit test the code, but now enough of talks, let’s try to explore the importance by coding it out.</p>
<p><strong>Note:</strong> All my examples below are written in <strong><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript">JavaScript</a></strong> and the unit test framework used is <strong><a target="_blank" href="https://jestjs.io/">Jest</a></strong>.</p>
<h3 id="example-1">Example 1:</h3>
<p>Let say, we want to write a function which gets two numbers as input, adds the and returns the result, as below:</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">addNumbers</span>(<span class="hljs-params">num1, num2</span>) </span>{
   <span class="hljs-keyword">return</span> num1 + num2;
}
</code></pre><p>And, we will write test cases for the above function. PFB the code for it:</p>
<pre><code><span class="hljs-attribute">expect</span>(addNumbers(<span class="hljs-number">5</span>, <span class="hljs-number">6</span>)).toBe(<span class="hljs-number">11</span>);
<span class="hljs-attribute">expect</span>(addNumbers(-<span class="hljs-number">1</span>, <span class="hljs-number">9</span>)).toBe(<span class="hljs-number">8</span>);
</code></pre><p>Till now, everything looks fine. We can pass two numbers and we get the desired result.</p>
<p>Next, imagine a situation where the consuming module forgot to pass parameters to <code>addNumbers</code> function. What should happen then? </p>
<p>Let’s say I want it to return 0 when any unexpected (undefined, null, string, etc.) value comes in. The current code will break because it will not return <code>0</code> when any unexpected inputs are passed to it. </p>
<p>Let's now go ahead and add more tests to handle these scenarios.</p>
<pre><code>// fails as <span class="hljs-keyword">with</span> <span class="hljs-keyword">current</span> implementation, <span class="hljs-keyword">result</span> will be <span class="hljs-keyword">NaN</span>
expect(addNumbers()).toBe(<span class="hljs-number">0</span>);

// fails as <span class="hljs-keyword">with</span> <span class="hljs-keyword">current</span> implementation, <span class="hljs-keyword">result</span> will be <span class="hljs-string">'abcxyz'</span> expect(addNumbers(<span class="hljs-string">'abc'</span>, <span class="hljs-string">'xyz'</span>)).toBe(<span class="hljs-number">0</span>);
</code></pre><p>When we run our test, these two test cases will break, since the actual result is different than what we had expected from this method. </p>
<p>So, we know that the code needs some modification to work properly and we go ahead and update the implementation, as below:</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">addNumbers</span>(<span class="hljs-params">num1, num2</span>) </span>{
   <span class="hljs-keyword">return</span> <span class="hljs-built_in">parseFloat</span>(num1 + num2) || <span class="hljs-number">0</span>;
}
</code></pre><p>Here, <code>parseFloat</code> will return <code>NaN</code> if we pass any non-number input and since <strong>NaN</strong> is a <strong>falsy</strong> value in JavaScript, the function will return 0 for these scenarios.</p>
<p>Now, all our test cases should pass, and if we had delivered this code today to production, we can sleep peacefully because we know that this method will not break any module from which it is getting consumed. What a relief, isn’t it 😎</p>
<h3 id="example-2">Example 2:</h3>
<p>Let’s consider we had a method which takes in <strong>userDetails</strong> as its argument and returns a new object, as below:</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getUserDetailsToDisplay</span>(<span class="hljs-params">userDetails</span>) </span>{
   <span class="hljs-keyword">return</span> {
     name: getFullName(userDetails.firstName, userDetails.lastName),
     dateOfBirth: userDetails.dob || <span class="hljs-string">'-'</span>
   };
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getFullName</span>(<span class="hljs-params">firstName = <span class="hljs-string">''</span>, lastName = <span class="hljs-string">''</span></span>) </span>{
   <span class="hljs-keyword">return</span> (firstName + <span class="hljs-string">' '</span> + lastName).trim() || <span class="hljs-string">'-'</span>; 
}
</code></pre><p>And the corresponding test case goes as below:</p>
<pre><code><span class="hljs-keyword">const</span> resultWithValidDetails = getUserDetailsToDisplay({
   firstName: <span class="hljs-string">'testFirstName'</span>,
   lastName: <span class="hljs-string">'testLastName'</span>, 
   dob: <span class="hljs-string">'test date'</span>
});
<span class="hljs-keyword">expect</span>(resultWithValidDetails.name).toBe(<span class="hljs-string">'testFirstName testLastName'</span>);
<span class="hljs-keyword">expect</span>(resultWithValidDetails.dateOfBirth).toBe(<span class="hljs-string">'test date'</span>);
<span class="hljs-keyword">const</span> resultWithNoDetails = getUserDetailsToDisplay({});
<span class="hljs-keyword">expect</span>(resultWithNoDetails.name).toBe(<span class="hljs-string">'-'</span>);
<span class="hljs-keyword">expect</span>(resultWithNoDetails.dateOfBirth).toBe(<span class="hljs-string">'-'</span>);
</code></pre><p>Next, a new requirement comes in, wherein, we need to show the <code>middleName</code> of the user as well. So we go and change the functionality of function <code>getUserDetailsToDisplay</code> as below:</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getUserDetailsToDisplay</span>(<span class="hljs-params">userDetails</span>) </span>{
   <span class="hljs-keyword">return</span> {
     name: getFullName(userDetails.firstName,     
           userDetails.middleName, userDetails.lastName),
     dateOfBirth: userDetails.dob || <span class="hljs-string">'-'</span>
   };
}
</code></pre><p>At this point, let say that we forgot to update the <code>getFullName</code> , and we also ignored any warning that we got. So If we had the test cases in place, they would start breaking, and this will alert us to examine the code in <strong>getFullName</strong>.</p>
<p>PFB the exact error we will get while running the tests:</p>
<p><img src="https://miro.medium.com/max/840/1*kQyyNwXdfkdfAO9jvTFx9g.png" alt="Error while running above test case which shows that expected and received objects are not same" /></p>
<p>Seeing this error, we understand there is an issue with our code, and we know exactly what is breaking. So, we could now go and fix the logic of computing names.</p>
<p>There could be a second scenario, where, if we are following TDD, we would have already updated the test cases to test the new changes as below:</p>
<pre><code><span class="hljs-keyword">const</span> resultWithValidDetails = getUserDetailsToDisplay({
   firstName: <span class="hljs-string">'testFirstName'</span>,
   middleName: <span class="hljs-string">'testMiddleName'</span>
   lastName: <span class="hljs-string">'testLastName'</span>, 
   dob: <span class="hljs-string">'test date'</span>
});
<span class="hljs-keyword">expect</span>(resultWithValidDetails.name).toBe(<span class="hljs-string">'testFirstName testMiddleName testLastName'</span>);
<span class="hljs-keyword">expect</span>(resultWithValidDetails.dateOfBirth).toBe(<span class="hljs-string">'test date'</span>);
</code></pre><p>But, these test cases would still fail, because the <strong>getFullName</strong> expects three parameters now, but we are only passing 2 of them in actual code. This is an example of easier debugging, we know where and what code block to debug based on the unit test case failed. PFB error in this case:</p>
<p><img src="https://miro.medium.com/max/840/1*EIR_G1Qf0yswN2pjJY3siw.png" alt="Snapshot of error for above use-case" /></p>
<p>Looking at error, again, we found out the mistake and could easily fix the code, let say, as below:</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getFullName</span>(<span class="hljs-params">firstName = <span class="hljs-string">''</span>, middleName = <span class="hljs-string">''</span>, lastName = <span class="hljs-string">''</span></span>) </span>{
   <span class="hljs-keyword">return</span> (firstName + <span class="hljs-string">' '</span> + middleName + <span class="hljs-string">' '</span> + lastName).trim() || 
          <span class="hljs-string">'-'</span>;
}
</code></pre><p>Now, all test cases should pass, and we should be good to go. So far, by writing unit tests, we have <strong>prevented two bugs in production</strong>, thereby reducing the cost of delivery (by avoiding the extra iteration of finding bug, fixing it, verifying it, and delivering it again to production). </p>
<blockquote>
<p>The quality of the code gets better when it is tested properly, and hence quite less prone to breaking our application/product.</p>
</blockquote>
<p>By now, at least you have some idea about how unit testing might help. Now, I know these might not be one of the greatest examples out there, but I purposefully kept it so simple, so that we are comfortable with the very idea of <strong>unit testing</strong>.</p>
<h3 id="conclusion">Conclusion</h3>
<p>If you ask of my take on it, unit tests should not be seen as an overhead or burden, instead, <em>we should embrace them as a daily practice and a healthy coding habit.</em></p>
<p>There have been many times where I have thanked my past self for writing that piece of test case which saved me from making a huge mistake and preventing an otherwise almost certain production bug.</p>
<p>Unit tests help us write better code and handle the multiple real-time scenarios quite well.</p>
<p>I always stress on the point to <strong>write logical test cases, and not to write it just for the sake of achieving that coverage goal</strong>, so that if anyone makes any design change in the component/function, the unit test should fail and that’s how any developer, new to that codebase, can understand what was the original purpose of that code.</p>
<p>This covers one more purpose of unit test, which is documentation of the code. <strong>Good unit test cases serve as documentation for future</strong> and it’s easy to maintain a codebase that is well documented and properly unit tested.</p>
<p>PFB one quote I once read on the web (I do not remember the author's name, but they must be a legend).</p>
<blockquote>
<p>Any code that is not unit tested is legacy code.</p>
</blockquote>
<p>So, if you want to ask me when should be the right time to start unit testing my code, the answer would be <strong>NOW!</strong></p>
<p><strong>Note:</strong> This article is the first of three articles I have on unit testing. PFB the series topics:</p>
<ol>
<li>Why should I unit test my code? (this article)</li>
<li>How should I unit test my code? (Setup and examples)</li>
<li>What should I unit test in my code?</li>
</ol>
<p>Stay tuned and catch you in the next article !! Any feedback is highly appreciable.</p>
<p>Thanks for reading. Stay safe, keep on learning and have a great day!!</p>
]]></content:encoded></item></channel></rss>