<?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 Sam Ho on Medium]]></title>
        <description><![CDATA[Stories by Sam Ho on Medium]]></description>
        <link>https://medium.com/@samhodev?source=rss-78b264a14e01------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*PzJtgUCvbcE04WqZrpRr9A.png</url>
            <title>Stories by Sam Ho on Medium</title>
            <link>https://medium.com/@samhodev?source=rss-78b264a14e01------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 15:02:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@samhodev/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 Get the Most Out of Opus 5.5]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@samhodev/how-to-get-the-most-out-of-opus-5-5-f38f9721d30d?source=rss-78b264a14e01------2"><img src="https://cdn-images-1.medium.com/max/1424/1*xx2zokI1Nkuvz8VUbTlb_w.jpeg" width="1424"></a></p><p class="medium-feed-snippet">Opus 5.5 is faster and smarter than before. It works over 30% quicker than Opus 5, often finishing the same job with fewer tokens.</p><p class="medium-feed-link"><a href="https://medium.com/@samhodev/how-to-get-the-most-out-of-opus-5-5-f38f9721d30d?source=rss-78b264a14e01------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@samhodev/how-to-get-the-most-out-of-opus-5-5-f38f9721d30d?source=rss-78b264a14e01------2</link>
            <guid isPermaLink="false">https://medium.com/p/f38f9721d30d</guid>
            <category><![CDATA[opus-5-5]]></category>
            <category><![CDATA[claude-opus]]></category>
            <category><![CDATA[generative-ai-tools]]></category>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[claude]]></category>
            <dc:creator><![CDATA[Sam Ho]]></dc:creator>
            <pubDate>Sun, 04 Oct 2026 00:33:38 GMT</pubDate>
            <atom:updated>2026-10-04T00:35:04.578Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Micro Frontend with Module Federation 2.0 in React (With a Working Example)]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@samhodev/micro-frontend-with-module-federation-2-0-in-react-with-a-working-example-e4cc87bcc9c6?source=rss-78b264a14e01------2"><img src="https://cdn-images-1.medium.com/max/1200/1*1VaPc90WfIVHKvnQ_Ys3mA.png" width="1200"></a></p><p class="medium-feed-link"><a href="https://medium.com/@samhodev/micro-frontend-with-module-federation-2-0-in-react-with-a-working-example-e4cc87bcc9c6?source=rss-78b264a14e01------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@samhodev/micro-frontend-with-module-federation-2-0-in-react-with-a-working-example-e4cc87bcc9c6?source=rss-78b264a14e01------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4cc87bcc9c6</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[implement-microfrontend]]></category>
            <category><![CDATA[micro-frontends]]></category>
            <category><![CDATA[react-microfrontend]]></category>
            <category><![CDATA[module-federation]]></category>
            <dc:creator><![CDATA[Sam Ho]]></dc:creator>
            <pubDate>Mon, 10 Aug 2026 19:26:07 GMT</pubDate>
            <atom:updated>2026-08-11T17:45:00.088Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How to Communicate Better (as a Software Engineer)]]></title>
            <link>https://medium.com/@samhodev/how-to-communicate-better-as-a-software-engineer-83d9dc7d74a8?source=rss-78b264a14e01------2</link>
            <guid isPermaLink="false">https://medium.com/p/83d9dc7d74a8</guid>
            <category><![CDATA[careers]]></category>
            <category><![CDATA[communication]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Sam Ho]]></dc:creator>
            <pubDate>Wed, 30 Oct 2024 16:33:02 GMT</pubDate>
            <atom:updated>2024-10-30T16:37:49.583Z</atom:updated>
            <content:encoded><![CDATA[<p>As an introvert who don’t like interacting with people, I find it extremely difficult to communicate well.</p><p>This extends to my career, when I realized myself not working well with the team, my product owner did not understand what I said, and my manager upset on me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YXB64gb9BOqXKf_K.jpg" /></figure><p>I start finding ways to improve my communication skills. I know this is extremely important for my career progression.</p><p>After 6 years as a software engineer, I finally got some basic understanding. Here is an effective communication framework that I have developed.</p><p>The general step of communication:</p><ul><li><strong>Stop</strong> <strong>talking</strong>. Put your mind ahead of your mouth.</li><li><strong>Know</strong> your audience.</li><li><strong>Listen</strong>. Ask probing question if needed.</li><li><strong>Think</strong>. Focus on helping others.</li><li><strong>Express</strong>. Keep it clear and concise.</li><li><strong>Reflect</strong>. Ask for feedback.</li></ul><p>Let’s deep dive on these with examples.</p><h3><strong>Stop</strong> <strong>talking</strong></h3><p>When I am being asked a question, as an engineer who knows everything I am being tampted to answer directly.</p><p>For example when my product owner ask:</p><blockquote>Can you explain how this feature will work?</blockquote><p>I used to anwer straight away and start giving out technical details. This is very bad, DON’T.</p><p>Instead, always put your mind ahead of your mouth.</p><h3><strong>Know</strong> your audience</h3><p>Understand who are you speaking to, because different audience require different approach. Ask the following question:</p><ul><li><strong><em>“What is their position?”</em></strong><em> — </em>Understand the position of the audience can reveal their needs, and the style of communication.</li><li><strong>“<em>What is their personality?” </em></strong><em>— </em>Understand the audience personality can help determining the style of communication.</li><li><strong>“<em>What is their goal?”</em></strong><em> — </em>Understand their goal can reveal their needs and wants.</li></ul><p>For example when my product owner ask:</p><blockquote>Can you explain how this feature will work?</blockquote><ul><li><em>“What is his position?” — </em>Product Owner. He need to know the feasibility of a new feature.</li><li>“<em>What is his personality?” — </em>Kind and friendly. I can choose a relaxing communication style.</li><li><em>“What is his goal?” — </em>Being a good product owner. He need to develop a great product, so he wants my help.</li></ul><h3><strong>Listen</strong>. Ask probing question if needed.</h3><p>Next, make sure you fully understand the question. You may ask probing questions if needed. Ask the following question:</p><ul><li><strong><em>“Why are they asking?” </em></strong><em>— </em>Understand the audience’s motivation behind</li><li><strong><em>“What is their idea?”</em></strong><em> —</em> Understand the intention behind</li><li><strong><em>“When/How do they need it?” </em></strong><em>— </em>Understand<em> </em>the audience’s expectation</li></ul><p>For example when my product owner ask:</p><blockquote>Can you explain how this feature will work?</blockquote><ul><li><em>“Why is he asking?”</em><strong><em> </em></strong><em>— </em>He wants my help to understand on the feature</li><li><em>“What is their idea?” — </em>He may wants to demo the feature, or may be thinking of how to improve it. I am not sure, so I will ask.</li><li><em>“When/How do they need it?”</em><strong><em> </em></strong><em>— </em>I will ask for more details.</li></ul><p>Usually there is a need to ask probing question, because the given information is not enough for the next step. Therefore, <strong>good communicators always ask probing question</strong>.</p><h3><strong>Think</strong>. Focus on helping others.</h3><p>After gathering enough information, it is time to think.</p><p>The first principle is to <strong>avoid self-centered mindset</strong>. What is it?</p><p>Self-centered mindset is the mindset that focus on yourself. (Note that self-center does not mean selfish, you may think you are being kind and helpful but actually self-centered)</p><p>For example, a self-centered enginner will think as follow:</p><blockquote>Q: Can you explain how this feature will work?</blockquote><blockquote>Thought: Why he asked? I developed this, I should know the best. Is he not trusting me?</blockquote><p>A self-centered person interpret this question as: <em>Do you have the knowledge on this feature? </em>And consider this question as a doubt of ability and knowledge.</p><p>This is too bad. Don’t think like that.</p><p>The second principle is to b<strong>e solution-orientated.</strong></p><p>Think of a solution which focus on how you can help the others. Understand other needs, and use your knowledge, to think of a solution that can solve their problem.</p><blockquote>Q: Can you explain how this feature will work?</blockquote><blockquote>Thought: He wants my help to understand on the feature, I can think of a solution! How about booking a demo with him?</blockquote><h3><strong>Express</strong>. Keep it clear and concise.</h3><p>It’s the time to demostrate your experise! But don’t get too excited. Remember to keep it clear and concise, and use a correct tone and style of communication. (From step 1: Know your audience)</p><blockquote>Q: Can you explain how this feature will work?</blockquote><blockquote>A: Of course, Chris! This feature is designed to act as an AI shop assistant, helping with a wide range of tasks. I am happy to walk you through with a demo.</blockquote><h3><strong>Reflect</strong>. Ask for feedback.</h3><p>Ask for feedback regularly. This can be asked through daily chat or even by sending out a form.</p><p>Ask the questions:</p><ul><li>How do you feel working with me?</li><li>What is the best way for our communication?</li><li>What do you think I can improve?</li></ul><h3>Thank You</h3><p>I will continue to write articles on career knowledge for senior engineer.</p><p>If you like this kind of article, please <strong>follow my </strong><a href="https://medium.com/@samhodev"><strong>Medium Page</strong></a><strong> </strong>so you can stay tuned. 🙂</p><p>Feel free to<strong> reach me through </strong><a href="https://www.linkedin.com/in/sam-hoooo/"><strong>LinkedIn</strong></a><strong> </strong>if you have any questions.<br>I hope you enjoy coding<strong>! </strong>👨‍💻</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83d9dc7d74a8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Keep Learning as a Software Engineer]]></title>
            <link>https://javascript.plainenglish.io/how-to-keep-learning-as-a-busy-software-engineer-f3c490cddacb?source=rss-78b264a14e01------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3c490cddacb</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[careers]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Sam Ho]]></dc:creator>
            <pubDate>Wed, 11 Sep 2024 23:29:13 GMT</pubDate>
            <atom:updated>2024-10-02T17:58:24.800Z</atom:updated>
            <content:encoded><![CDATA[<p>Even when you are overwhelmed at work</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zvol3HiYxhfoUOaSnKRBoQ.png" /></figure><p>Discover how to keep learning and growing as a software engineer, even when you are short on time.</p><h3>Always Learning</h3><p>What programming languages and frameworks are you using in your job?</p><blockquote>Javascript, NodeJS, React, NextJS, GraphQL…</blockquote><p>They may be popular now, and they seem to have a positive outlook for the next few years, but we cannot predict the future.</p><p>The only way to stay relevant is to keep learning new things and adapt to trends.</p><p>Without it, you risk falling behind — and so does your career.</p><blockquote>But I don’t have time.</blockquote><p>No, you actually have more time than you think. Here’s how you can stay ahead in your career by making the best use of your time.</p><h3><strong>Learn in Your Job</strong></h3><p>Your current job can be one of the best places to learn if you approach it the right way. Instead of rushing to meet deadlines, look for opportunities to stretch yourself.</p><h4><strong>Protect your learning time</strong></h4><p>In your daily work schedule, try to free up 30 minutes to an hour for dedicated learning. The best time might be when you have no meetings but don’t feel quite ready to start coding.</p><p>You can also talk to your manager about allocating this time: <strong>Remember,</strong> <strong>your company is paying for quality work, not just your time. </strong>Sharpen your skill with a dedicated learning time benefits your company as well.</p><h4>Learn from peers</h4><p>When reviewing PR, instead of giving a LGTM (Look good to me) and approval without much thought, take the time to truly understand the work. Consider how you would have approached the task if it were assigned to you. How does your approach differ from your peer’s? If you are confused about something, don’t hesitate to jump on a call with your colleague to clarify.</p><p>Pair programming is another great way to see how others solve problems and pick up new techniques. When paired with someone more experienced, you can take on challenges outside your comfort zone and feel confident knowing you have a safety net to catch potential errors.</p><blockquote>When you meet someone smarter than you, don’t compete. Learn.</blockquote><h4>Take a challenge</h4><p>When you take on tasks that stretch your abilities, you are forced to push beyond your current skill set and adapt to new problem domains. This hands-on experience teaches you in ways that tutorials or books simply can’t.</p><blockquote>Aside from your salary, hands-on experience is the most valuable asset you can gain from your company.</blockquote><p>Start by identifying growth opportunities. Look for projects that align with skills you want to develop. For example, if you are a frontend engineer who wants to sharpen backend skills, look for full-stack projects.</p><p>If you are working on one, don’t be afraid to make mistakes — that’s where the learning happens. Embrace the Learning Curve.</p><h4><strong>Work on open source project</strong></h4><p>If you can’t find challenging projects that align with your goals, try looking outwards. Contributing to open-source projects is a great way to learn from experienced engineers and add to your portfolio. Look for a “good first issue” label on GitHub to get started. This allows you to tackle beginner-friendly tasks and gradually build your confidence.</p><p><a href="https://github.com/MunGell/awesome-for-beginners">GitHub - MunGell/awesome-for-beginners: A list of awesome beginners-friendly projects.</a></p><h3><strong>Prioritize Consistency Over Quantity</strong></h3><p>It’s easy to feel pressured to master everything at once, but real progress comes from consistency. Set achievable daily goals and pace yourself. If you’re tired, it’s okay to pick lighter tasks. What matters is that you are improving continuously.</p><p>Remember, it’s about the journey, not a sprint. Over time, all the small efforts will add up, and you will see the hard work pay off.</p><blockquote>Persistence reveals the pathway to success</blockquote><h3>Thank You</h3><p>I will continue to write articles on frontend knowledge for senior engineer.</p><p>If you like this kind of article, please <strong>follow my </strong><a href="https://medium.com/@samhodev"><strong>Medium Page</strong></a><strong> </strong>so you can stay tuned. 🙂</p><p>Feel free to<strong> reach me through </strong><a href="https://www.linkedin.com/in/sam-hoooo/"><strong>LinkedIn</strong></a><strong> </strong>if you have any questions.<br>I hope you enjoy coding<strong>! </strong>👨‍💻</p><h3>In Plain English 🚀</h3><p><em>Thank you for being a part of the </em><a href="https://plainenglish.io/"><strong><em>In Plain English</em></strong></a><em> community! Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://twitter.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a></li><li>Visit our other platforms: <a href="https://cofeed.app/"><strong>CoFeed</strong></a> | <a href="https://differ.blog/"><strong>Differ</strong></a></li><li>More content at <a href="https://plainenglish.io/"><strong>PlainEnglish.io</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3c490cddacb" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/how-to-keep-learning-as-a-busy-software-engineer-f3c490cddacb">How to Keep Learning as a Software Engineer</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to write better JEST tests]]></title>
            <link>https://javascript.plainenglish.io/how-to-write-tests-using-jest-the-best-practice-99a5d207be87?source=rss-78b264a14e01------2</link>
            <guid isPermaLink="false">https://medium.com/p/99a5d207be87</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[jest]]></category>
            <dc:creator><![CDATA[Sam Ho]]></dc:creator>
            <pubDate>Wed, 28 Aug 2024 16:55:46 GMT</pubDate>
            <atom:updated>2024-09-25T22:54:21.041Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*qH7Nn9e7WoIHthVU.png" /></figure><p>Writing test script is an essential skill for a senior engineer, and when it comes to testing React components, <a href="https://jestjs.io/">Jest</a> is one of the most popular frameworks out there.</p><p>This article will provide insights into the best practices when using Jest to test React applications, to keep your test cases concise, accurate and bring out real confidence.</p><h3>1. Organize Your Tests</h3><p><strong>Group Tests into Folders</strong></p><p>Keeping tests organized is crucial for maintaining clarity in your project. It’s common practice to have a dedicated __tests__ directory or to place test files alongside the files they are testing. For instance:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*ZrR6gGomZzfllbIAQQEBdw.png" /></figure><ul><li>src/components/Button/Button.tsx</li><li>src/components/Button/Button.test.tsx</li></ul><p>This structure makes it easy to locate test files related to specific components.</p><p><strong>Use Descriptive Names</strong></p><p>Test files should follow a consistent naming convention, typically ending in .test.js. Descriptive names help quickly identify what each test is covering:</p><pre>Button.test.js<br>Button.test.ts<br>Button.test.tsx</pre><h3>2. Test Behavior, Not Implementation</h3><p><strong>Focus on What the Component Does</strong></p><p>Your tests should verify that the component behaves as expected, not how it achieves that behavior.</p><p>This approach ensures that refactoring internal implementation doesn’t require rewriting tests, as long as the output remains consistent.</p><pre>// Instead of testing internal methods, test user interactions and component output<br>test(&#39;button click calls onClick handler&#39;, () =&gt; {<br>  const handleClick = jest.fn();<br>  render(&lt;Button onClick={handleClick} label=&quot;Click Me&quot; /&gt;);<br>  fireEvent.click(screen.getByText(&#39;Click Me&#39;));<br>  expect(handleClick).toHaveBeenCalledTimes(1);<br>});</pre><p><strong>Avoid Testing Internal State</strong></p><p>Instead of testing the internal state directly, test what the user sees and interacts with. For example, check that the UI updates correctly when the state changes, rather than testing the state itself.</p><h3>3. Write Readable and Maintainable Tests</h3><p><strong>Use Descriptive Test Names</strong></p><p>Test names should be descriptive and convey the behavior being tested. A good test name can serve as documentation for the functionality.</p><pre>describe(&#39;Checkout button&#39;, () =&gt; {<br>  it(&#39;should calls place order handler when clicked&#39;, () =&gt; {<br>    // test logic<br>  });<br>}</pre><p><strong>Follow the Arrange-Act-Assert Pattern</strong></p><p>The Arrange-Act-Assert (AAA) pattern makes tests easy to read and understand. It involves three steps:</p><ol><li><strong>Arrange</strong>: Set up the initial state and environment.</li><li><strong>Act</strong>: Perform the action that triggers the behavior you want to test.</li><li><strong>Assert</strong>: Check if the outcomes match your expectations.</li></ol><pre>test(&#39;should increment counter&#39;, () =&gt; {<br>  // Arrange<br>  render(&lt;Counter /&gt;);<br>  <br>  // Act<br>  fireEvent.click(screen.getByText(&#39;Increment&#39;));<br>  <br>  // Assert<br>  expect(screen.getByText(&#39;Count: 1&#39;)).toBeInTheDocument();<br>});</pre><h3>4. <strong>Use Snapshots Wisely</strong></h3><p><strong>Keep Snapshots Focused</strong></p><p>Snapshot testing is a powerful feature in Jest that captures the rendered output of components.</p><pre>import { render } from &#39;@testing-library/react&#39;;<br>import Button from &#39;./Button&#39;;<br><br>test(&#39;matches snapshot&#39;, () =&gt; {<br>  const { asFragment } = render(&lt;Button label=&quot;Click Me&quot; /&gt;);<br>  expect(asFragment()).toMatchSnapshot();<br>});</pre><p>You should only use snapshot if:</p><ul><li>The component you are testing is small (e.g. Button, Header Text).</li><li>The snapshot generated is not too large.</li></ul><h3>5. Mocking and Spying</h3><p><strong>Use Jest Mock Functions for Callbacks</strong></p><p>When testing interactions, mock functions (jest.fn()) can verify that callbacks are called with the expected arguments.</p><pre>test(&#39;calls the provided onClick handler&#39;, () =&gt; {<br>  const onClickMock = jest.fn();<br>  render(&lt;Button onClick={onClickMock} label=&quot;Click Me&quot; /&gt;);<br>  <br>  fireEvent.click(screen.getByText(&#39;Click Me&#39;));<br>  expect(onClickMock).toHaveBeenCalledTimes(1);<br>});</pre><p><strong>Use </strong><strong>jest.spyOn() to Monitor Function Calls</strong></p><p>jest.spyOn() is useful for observing function calls and understanding how components interact with other parts of the application.</p><pre>import * as api from &#39;./api&#39;;<br><br>test(&#39;calls API to fetch data&#39;, async () =&gt; {<br>  jest.spyOn(api, &#39;fetchData&#39;).mockResolvedValue({ data: [] });<br>  <br>  // Trigger function that calls `fetchData`<br>  expect(api.fetchData).toHaveBeenCalledTimes(1);<br>});</pre><h3>6. <strong>Asynchronous Testing</strong></h3><p><strong>Use Async/Await for Async Operations</strong></p><p>When dealing with asynchronous code, use async and await for a clean and readable test flow.</p><pre>test(&#39;fetches and displays data&#39;, async () =&gt; {<br>  const mockData = { data: &#39;Hello World&#39; };<br>  axios.get.mockResolvedValue({ data: mockData });<br>  <br>  render(&lt;DataComponent /&gt;);<br>  <br>  // Wait for the element to appear<br>  expect(await screen.findByText(&#39;Hello World&#39;)).toBeInTheDocument();<br>});</pre><p><strong>Avoid Race Conditions with Proper Cleanup</strong></p><p>Ensure asynchronous operations are properly cleaned up to avoid race conditions or memory leaks. This is especially important in component unmounting.</p><pre>afterEach(() =&gt; {<br>   // cleaning up the mess left behind the previous test<br>   mockAxios.reset();<br>});</pre><h3>Thank You</h3><p>I will continue to write articles on frontend knowledge for senior engineer.</p><p>If you like this kind of article, please <strong>follow my Medium Page </strong>so you can stay tuned. 🙂</p><p>Feel free to<strong> reach me through </strong><a href="https://www.linkedin.com/in/sam-hoooo/"><strong>LinkedIn</strong></a><strong> </strong>if you have any questions.<br>I hope you enjoy coding<strong>! </strong>👨‍💻</p><h3>In Plain English 🚀</h3><p><em>Thank you for being a part of the </em><a href="https://plainenglish.io/"><strong><em>In Plain English</em></strong></a><em> community! Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://twitter.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a></li><li>Visit our other platforms: <a href="https://cofeed.app/"><strong>CoFeed</strong></a> | <a href="https://differ.blog/"><strong>Differ</strong></a></li><li>More content at <a href="https://plainenglish.io/"><strong>PlainEnglish.io</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99a5d207be87" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/how-to-write-tests-using-jest-the-best-practice-99a5d207be87">How to write better JEST tests</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mocking GraphQL request in React using Mock Service Worker]]></title>
            <link>https://javascript.plainenglish.io/mocking-graphql-request-in-react-using-mock-service-worker-494423507ea5?source=rss-78b264a14e01------2</link>
            <guid isPermaLink="false">https://medium.com/p/494423507ea5</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[mock-service-worker]]></category>
            <category><![CDATA[graphql]]></category>
            <dc:creator><![CDATA[Sam Ho]]></dc:creator>
            <pubDate>Wed, 14 Aug 2024 22:36:31 GMT</pubDate>
            <atom:updated>2024-09-16T00:51:11.717Z</atom:updated>
            <content:encoded><![CDATA[<p>Learn how to mock GraphQL request in your React project using Mock Service Worker (MSW).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AqnGTNiPREd-wFzwbGEchA.png" /></figure><p>When we develop frontend, often need to test our code with API to ensure functionality. However, it could be particularly challenging in early phases where backend is still under construction.</p><p><strong>Why?</strong></p><ul><li>Frontend engineers depends on backend API to spin up their code.</li><li>Backend API is unstable, causing frontend to break unexpectedly.</li><li>Backend API response is too slow to run tests on CI pipeline.</li></ul><p>This is where <a href="https://github.com/mswjs/msw"><strong>Mock Service Worker (MSW)</strong></a> shines. MSW is a powerful tool that intercepts network requests at the browser level, allowing you to mock API responses seamlessly.</p><h3>What is Mock Service Worker (MSW)?</h3><p>Mock Service Worker is a JavaScript library that intercepts HTTP requests made by your web application and allows you to mock responses directly in the browser. This approach is especially useful for testing because it provides an environment close to production without relying on external APIs or server dependencies.</p><p>Unlike other mocking tools, MSW operates on the service worker level, meaning that it can handle requests even before they reach your backend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/0*jq8rsC0QrZyUyqyv" /><figcaption>Source: MSW documentation <a href="https://v1.mswjs.io/docs/">https://v1.mswjs.io/docs/</a></figcaption></figure><p>MSW supports both REST and GraphQL APIs mocking, today we focus on GraphQL mocking.</p><h3>Setting Up MSW in a React Application</h3><p>To get started with MSW in a React project, you’ll need to install the library and configure it for use with GraphQL. Let’s walk through the steps. <a href="https://66bd25db614215078fc4a3d2--msw-graphql-mocking.netlify.app/">Complete demo</a></p><h4>1. Install MSW</h4><p>First, you need to install MSW as a dependency in your React project:</p><pre>npm install msw@^1.3.3 --save-dev</pre><p>Alternatively, if you’re using Yarn:</p><pre>yarn add -D msw@^1.3.3</pre><h4>2. Create a Service Worker</h4><p>Next, you’ll need to create and initialize the service worker for MSW. Run the following command to generate the service worker file:</p><pre>npx msw init &lt;PUBLIC_DIR&gt;</pre><p>Where <strong>&lt;PUBLIC_DIR&gt;</strong> is your React public directory. In my demo, it is:</p><pre>npx msw init ./public</pre><p>This command creates a service worker file in the public directory of your React application.</p><h4>3. Define GraphQL Request Handlers</h4><p>With the service worker set up, the next step is to define the handlers for your GraphQL queries and mutations. Create a file named mocks/handlers.js in your project:</p><pre>import { graphql } from &quot;msw&quot;;<br><br>export const handlers = [<br>  // Handles a mutation to update user name<br>  graphql.mutation(&quot;UpdateUserInfo&quot;, (req, res, ctx) =&gt; {<br>    const { username } = req.variables;<br>    sessionStorage.setItem(&quot;username&quot;, username);<br><br>    return res(<br>      ctx.data({<br>        user: {<br>          username,<br>        },<br>      })<br>    );<br>  }),<br><br>  // Handles a query to return user name<br>  graphql.query(&quot;GetUserInfo&quot;, (_, res, ctx) =&gt; {<br>    const username = sessionStorage.getItem(&quot;username&quot;);<br><br>    return res(<br>      ctx.data({<br>        user: {<br>          username: username,<br>        },<br>      })<br>    );<br>  }),<br>];</pre><p>In this example, we’re defining two handlers:</p><ul><li>GetUserInfo: Mocks a GraphQL query that retrieves user name.</li><li>UpdateUserInfo: Mocks a GraphQL mutation that updates user name.</li></ul><p>The graphql.query and graphql.mutation functions are used to define the type of operation being mocked. The res and ctx objects allow you to control the response data.</p><h4>4. Integrate MSW in Your Application</h4><p>Once you have defined the request handlers, you will need to set up MSW in your application. This is typically done in your application’s entry file (src/index.js or src/main.js):</p><pre>import React from &quot;react&quot;;<br>import ReactDOM from &quot;react-dom/client&quot;;<br>import &quot;./index.css&quot;;<br>import App from &quot;./App&quot;;<br><br>if (process.env.NODE_ENV === &#39;development&#39;) {<br>  const { worker } = require(&quot;./mocks/browser&quot;);<br>  worker.start();<br>}<br><br>const root = ReactDOM.createRoot(document.getElementById(&quot;root&quot;));<br>root.render(<br>  &lt;React.StrictMode&gt;<br>    &lt;App /&gt;<br>  &lt;/React.StrictMode&gt;<br>);</pre><p>And then, create the browser.js file where the service worker is initialized:</p><pre>// src/mocks/browser.js<br>import { setupWorker } from &quot;msw&quot;;<br>import { handlers } from &quot;./handlers&quot;;<br><br>// This configures a Service Worker with the given request handlers.<br>export const worker = setupWorker(...handlers);</pre><h3>Testing GraphQL Requests with MSW</h3><p>With MSW set up, you can now proceed to set up a form to submit request to your GraphQL endpoint:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/290/1*N2g_qBIH0ZacSxe2qznsIA.png" /></figure><p>Your GraphQL requests should be intercepted by MSW. You can check this in your browser dev tools:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*zszUJAI_y-IVLXPSlo9Naw.png" /></figure><p>By opening the log, you can even check the request and response bodies going through MSW:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*et5SNUsy9sg5u1cUJK1Hbw.png" /></figure><p>In the network tab of dev tools, you can see actual requests are intercepted by service worker:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sPMFc5aPaOmCrXwSL6FMbA.png" /></figure><p>Which means MSW intercepts these requests, and they never reach to your real backend API endpoint ! (https://flyby-router-demo.herokuapp.com/)</p><h3>Useful Resources</h3><p>The full source code is avaliable in my Github repository.</p><p><a href="https://github.com/samhoooo/msw-playground">GitHub - samhoooo/msw-playground: Mock Service Worker (MSW) to mock GraphQL API in React App</a></p><h3>Thank You</h3><p>I will continue to write articles on frontend knowledge for senior engineer.</p><p>If you like this kind of article, please <strong>follow my Medium Page </strong>so you can stay tuned. 🙂</p><p>Feel free to<strong> reach me through </strong><a href="https://www.linkedin.com/in/sam-hoooo/"><strong>LinkedIn</strong></a><strong> </strong>if you have any questions.<br>I hope you enjoy coding<strong>! </strong>👨‍💻</p><h3>In Plain English 🚀</h3><p><em>Thank you for being a part of the </em><a href="https://plainenglish.io/"><strong><em>In Plain English</em></strong></a><em> community! Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://twitter.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a></li><li>Visit our other platforms: <a href="https://cofeed.app/"><strong>CoFeed</strong></a> | <a href="https://differ.blog/"><strong>Differ</strong></a></li><li>More content at <a href="https://plainenglish.io/"><strong>PlainEnglish.io</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=494423507ea5" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/mocking-graphql-request-in-react-using-mock-service-worker-494423507ea5">Mocking GraphQL request in React using Mock Service Worker</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to build AI Chatbot on your website with Ollama]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@samhodev/how-to-build-ai-chatbot-on-your-website-with-ollama-79c182deeba3?source=rss-78b264a14e01------2"><img src="https://cdn-images-1.medium.com/max/1168/0*-9J6J-vqMDaHr174.png" width="1168"></a></p><p class="medium-feed-snippet">Learn how to build a web chatbot using Next.js with Ollama. Step by step example with source code.</p><p class="medium-feed-link"><a href="https://medium.com/@samhodev/how-to-build-ai-chatbot-on-your-website-with-ollama-79c182deeba3?source=rss-78b264a14e01------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@samhodev/how-to-build-ai-chatbot-on-your-website-with-ollama-79c182deeba3?source=rss-78b264a14e01------2</link>
            <guid isPermaLink="false">https://medium.com/p/79c182deeba3</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Sam Ho]]></dc:creator>
            <pubDate>Mon, 22 Jul 2024 17:02:34 GMT</pubDate>
            <atom:updated>2024-07-24T12:19:02.436Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Zustand: How is it better than React Context (with an example)]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@samhodev/zustand-how-is-it-better-than-react-context-with-an-example-24dad4c65753?source=rss-78b264a14e01------2"><img src="https://cdn-images-1.medium.com/max/1200/0*YN7o1xnDKw2QFXC1.jpg" width="1200"></a></p><p class="medium-feed-snippet">As a web engineer, you may be in a situation where you need to manage the state of your application. When comes to state management, there&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@samhodev/zustand-how-is-it-better-than-react-context-with-an-example-24dad4c65753?source=rss-78b264a14e01------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@samhodev/zustand-how-is-it-better-than-react-context-with-an-example-24dad4c65753?source=rss-78b264a14e01------2</link>
            <guid isPermaLink="false">https://medium.com/p/24dad4c65753</guid>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[zustand]]></category>
            <dc:creator><![CDATA[Sam Ho]]></dc:creator>
            <pubDate>Fri, 12 Apr 2024 21:22:46 GMT</pubDate>
            <atom:updated>2024-04-12T21:22:46.604Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Signals — Future of React State Management]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@samhodev/signals-future-of-react-state-management-f4b04b897c9e?source=rss-78b264a14e01------2"><img src="https://cdn-images-1.medium.com/max/1200/0*ywfz3SOkezF2xpS8" width="1200"></a></p><p class="medium-feed-snippet">Preact/Signals is a library which is getting more popular. It shifts frontend development towards a more intuitive way of handling state.</p><p class="medium-feed-link"><a href="https://medium.com/@samhodev/signals-future-of-react-state-management-f4b04b897c9e?source=rss-78b264a14e01------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@samhodev/signals-future-of-react-state-management-f4b04b897c9e?source=rss-78b264a14e01------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4b04b897c9e</guid>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[preactjs]]></category>
            <dc:creator><![CDATA[Sam Ho]]></dc:creator>
            <pubDate>Fri, 01 Mar 2024 17:34:21 GMT</pubDate>
            <atom:updated>2024-09-25T22:02:36.575Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How to build your self-hosted Chatbot]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@samhodev/how-to-build-your-own-chatbot-b43553d0b0d5?source=rss-78b264a14e01------2"><img src="https://cdn-images-1.medium.com/max/960/1*v5eTxCRRf3E-N4K-4Lv9Kg.jpeg" width="960"></a></p><p class="medium-feed-snippet">No third-party API, you own your data. Using Amazon Sagemaker. Running on Web interface. With code and demo.</p><p class="medium-feed-link"><a href="https://medium.com/@samhodev/how-to-build-your-own-chatbot-b43553d0b0d5?source=rss-78b264a14e01------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@samhodev/how-to-build-your-own-chatbot-b43553d0b0d5?source=rss-78b264a14e01------2</link>
            <guid isPermaLink="false">https://medium.com/p/b43553d0b0d5</guid>
            <category><![CDATA[self-hosted]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[sagemaker]]></category>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[chatbots]]></category>
            <dc:creator><![CDATA[Sam Ho]]></dc:creator>
            <pubDate>Tue, 26 Dec 2023 21:47:38 GMT</pubDate>
            <atom:updated>2024-04-22T14:07:03.825Z</atom:updated>
        </item>
    </channel>
</rss>