<?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 Richa Sinha on Medium]]></title>
        <description><![CDATA[Stories by Richa Sinha on Medium]]></description>
        <link>https://medium.com/@sinha.richa08?source=rss-c1366fe51c1c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*JT3iAPs6fxBxB4U9moUEjw.jpeg</url>
            <title>Stories by Richa Sinha on Medium</title>
            <link>https://medium.com/@sinha.richa08?source=rss-c1366fe51c1c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 19:11:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sinha.richa08/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[Jest Series Part 2— Testing a react custom hook]]></title>
            <link>https://medium.com/@sinha.richa08/jest-series-part-2-testing-a-react-custom-hook-cb93244f64f2?source=rss-c1366fe51c1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb93244f64f2</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[custom-hook]]></category>
            <category><![CDATA[tdd]]></category>
            <category><![CDATA[jest]]></category>
            <dc:creator><![CDATA[Richa Sinha]]></dc:creator>
            <pubDate>Sat, 10 May 2025 10:35:17 GMT</pubDate>
            <atom:updated>2025-05-10T10:40:27.800Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yUNxC_PDNWtZMdqO" /><figcaption>Photo by <a href="https://unsplash.com/@marliesestreefland?utm_source=medium&amp;utm_medium=referral">Milli</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In the last story, we saw how to test a react hook with multiple fetch calls in <a href="https://medium.com/@sinha.richa08/jest-series-part-1-testing-react-components-with-one-or-more-fetch-calls-b430da0f0d16">Jest Series Part 1 — Testing React Components with one or more fetch calls</a></p><p>Noew, lets create a custom hook and test it.</p><p>The useUserData hook fetches data from one endpoint (/users/1). It manages three state variables: user (for the fetched data), loading (a boolean indicating if the data is still loading), and error (to store any error message if the fetch fails).</p><pre>import { useState, useEffect } from &#39;react&#39;;<br><br>interface User {<br>  name: string;<br>  email: string;<br>}<br><br>interface UseUserDataReturn {<br>  user: User | null;<br>  loading: boolean;<br>  error: string | null;<br>}<br><br>const useUserData = (): UseUserDataReturn =&gt; {<br>  const [user, setUser] = useState&lt;User | null&gt;(null);<br>  const [loading, setLoading] = useState&lt;boolean&gt;(true);<br>  const [error, setError] = useState&lt;string | null&gt;(null);<br><br>  useEffect(() =&gt; {<br>    const fetchUserData = async () =&gt; {<br>      try {<br>        const response = await fetch(&#39;https://jsonplaceholder.typicode.com/users/1&#39;);<br>        if (!response.ok) {<br>          throw new Error(&#39;Network response was not ok&#39;);<br>        }<br>        const data = await response.json();<br>        setUser(data);<br>      } catch (err) {<br>        setError(&#39;Error fetching user data&#39;);<br>        console.error(&#39;Error fetching user data:&#39;, err);<br>      } finally {<br>        setLoading(false);<br>      }<br>    };<br><br>    fetchUserData();<br>  }, []);<br><br>  return { user, loading, error };<br>};<br><br>export default useUserData;</pre><p>To test this hook, we will render this hook and test for loading state, successful fetch and error handling.</p><pre>import { renderHook } from &#39;@testing-library/react-hooks&#39;;<br>import useUserData from &#39;./useUserData&#39;;<br><br>describe(&#39;useUserData Hook&#39;, () =&gt; {<br>  beforeEach(() =&gt; {<br>    jest.mocked(window.fetch).mockImplementation((input, _init) =&gt; {<br>      if (input.toString().includes(&#39;/users/1&#39;)) {<br>        return Promise.resolve({<br>          ok: true,<br>          json: () =&gt;<br>            Promise.resolve({<br>              name: &#39;Leanne Graham&#39;,<br>              email: &#39;leanne@example.com&#39;,<br>            }),<br>        } as Response);<br>      }<br>      return Promise.reject(new Error(&#39;Unexpected fetch call&#39;));<br>    });<br>  });<br><br>  afterEach(() =&gt; {<br>    jest.restoreAllMocks();<br>  });<br><br>  it(&#39;returns loading as true initially, then false after fetching&#39;, async () =&gt; {<br>    const { result, waitForNextUpdate } = renderHook(() =&gt; useUserData());<br>    expect(result.current.loading).toBe(true);<br>    await waitForNextUpdate();<br>    expect(result.current.loading).toBe(false);<br>  });<br><br>  it(&#39;returns user data after fetching&#39;, async () =&gt; {<br>    const { result, waitForNextUpdate } = renderHook(() =&gt; useUserData());<br>    await waitForNextUpdate();<br>    expect(result.current.user).toEqual({<br>      name: &#39;Leanne Graham&#39;,<br>      email: &#39;leanne@example.com&#39;,<br>    });<br>  });<br><br>  it(&#39;handles errors correctly&#39;, async () =&gt; {<br>    jest.mocked(window.fetch).mockRejectedValueOnce(new Error(&#39;Fetch error&#39;));<br><br>    const { result, waitForNextUpdate } = renderHook(() =&gt; useUserData());<br>    await waitForNextUpdate();<br><br>    expect(result.current.error).toBe(&#39;Error fetching user data&#39;);<br>  });<br>});</pre><p>Notice how we render the hook by using ‘@testing-library/react-hooks’ library.</p><p>One more thing to note here is, if your hook has an asynchronous operation inside it and there are some assertions that you need to make after that operation is complete, you need to use await waitForNextUpdate().</p><p>Next up: testing a react component and hook with context or providers.</p><p>See you..</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb93244f64f2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jest Series Part 1 — Testing React Components with one or more fetch calls]]></title>
            <link>https://medium.com/@sinha.richa08/jest-series-part-1-testing-react-components-with-one-or-more-fetch-calls-b430da0f0d16?source=rss-c1366fe51c1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/b430da0f0d16</guid>
            <category><![CDATA[react-testing-library]]></category>
            <category><![CDATA[jest]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[fetch]]></category>
            <dc:creator><![CDATA[Richa Sinha]]></dc:creator>
            <pubDate>Sat, 10 May 2025 05:25:32 GMT</pubDate>
            <atom:updated>2025-05-10T10:39:04.138Z</atom:updated>
            <content:encoded><![CDATA[<h3>Jest Series Part 1 — Testing React Components with one or more fetch calls</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_IFS24drIRS7mHpC" /><figcaption>Photo by <a href="https://unsplash.com/@dogflirt?utm_source=medium&amp;utm_medium=referral">Anthony Duran</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Hey there, fellow developers!</p><p>Today, we’re diving into the world of Jest testing in React. If you’re new to testing or just looking to brush up on your skills, this series is for you. We’ll start with a simple component that makes a fetch call and write a test suite using Jest and React Testing Library (RTL) to ensure everything works as expected.</p><p>Let’s get started!</p><h3>Creating a Simple React Component</h3><p>First things first, let’s create a simple React component that fetches data from an API. We’ll call this component UserProfile. It will fetch user data from a mock API and display the user&#39;s name and email.</p><pre>import { useState, useEffect } from &#39;react&#39;;<br><br>const UserProfile: React.FC = () =&gt; {<br>  const [user, setUser] = useState&lt;{ name: string; email: string } | null&gt;(null);<br>  const [error, setError] = useState&lt;string | null&gt;(null);<br><br>  useEffect(() =&gt; {<br>    const fetchUserData = async () =&gt; {<br>      try {<br>        const response = await fetch(&#39;https://jsonplaceholder.typicode.com/users/1&#39;);<br>        if (!response.ok) {<br>          throw new Error(&#39;Network response was not ok&#39;);<br>        }<br>        const data = await response.json();<br>        setUser(data);<br>      } catch (error) {<br>        setError(&#39;Failed to fetch user data&#39;);<br>      }<br>    };<br><br>    fetchUserData();<br>  }, []);<br><br>  if (error) {<br>    return &lt;div&gt;{error}&lt;/div&gt;;<br>  }<br><br>  if (!user) {<br>    return &lt;div&gt;Loading...&lt;/div&gt;;<br>  }<br><br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;{user.name}&lt;/h1&gt;<br>      &lt;p&gt;{user.email}&lt;/p&gt;<br>    &lt;/div&gt;<br>  );<br>};<br><br>export default UserProfile;</pre><p>no React import (import React from “react”) ?? 😳</p><p>Since React 17, the new JSX transform automatically imports the necessary React functions in the compiled output, so you no longer need to explicitly import React at the top of every component file.</p><p>Lets move forward..</p><h3>Writing Tests with Jest and RTL</h3><p>Now that we have our component, let’s write some tests to ensure it behaves correctly. We’ll use Jest for our test framework and React Testing Library for rendering and querying the component.</p><pre>import { render, screen, waitFor } from &#39;@testing-library/react&#39;;<br>import UserProfile from &#39;./UserProfile&#39;;<br><br>describe(&#39;UserProfile Component&#39;, () =&gt; {<br>  beforeEach(() =&gt; {<br>    jest.mocked(window.fetch).mockResolvedValue({<br>      ok: true,<br>      json: () =&gt; Promise.resolve({<br>        name: &#39;Leanne Graham&#39;,<br>        email: &#39;leanne@example.com&#39;,<br>      }),<br>    } as Response);<br>  });<br><br>  afterEach(() =&gt; {<br>    jest.restoreAllMocks();<br>  });<br><br>  it(&#39;displays loading initially&#39;, () =&gt; {<br>    render(&lt;UserProfile /&gt;);<br>    expect(screen.getByText(/loading/i)).toBeInTheDocument();<br>  });<br><br>  it(&#39;displays user data after fetch&#39;, async () =&gt; {<br>    render(&lt;UserProfile /&gt;);<br>    await waitFor(() =&gt; expect(screen.getByText(&#39;Leanne Graham&#39;)).toBeInTheDocument());<br>    expect(screen.getByText(&#39;leanne@example.com&#39;)).toBeInTheDocument();<br>    expect(window.fetch).toHaveBeenCalled();<br>  });<br><br>  it(&#39;handles fetch errors gracefully&#39;, async () =&gt; {<br>    jest.mocked(window.fetch).mockRejectedValueOnce(new Error(&quot;Unexpected fetch call&quot;));<br><br>    render(&lt;UserProfile /&gt;);<br>    await waitFor(() =&gt; {<br>      expect(window.fetch).toHaveBeenCalled();<br>      expect(screen.getByText(/loading/i)).toBeInTheDocument();<br>    });<br><br>    await waitFor(() =&gt; expect(screen.getByText(/failed to fetch user data/i)).toBeInTheDocument());<br>  });<br>});</pre><p>`await waitFor` is used to asynchronously wait for changes in the component’s state or DOM that occur after asynchronous operations, like fetch calls, ensuring that assertions are made only after the component has fully updated and rendered the expected output.</p><p>What if there are multiple fetch calls? 🤔<br>How to mock those?</p><p>Let’s see an example:</p><pre>import { useState, useEffect } from &#39;react&#39;;<br><br>interface User {<br>  name: string;<br>  email: string;<br>}<br><br>interface Post {<br>  id: number;<br>  title: string;<br>  body: string;<br>}<br><br>const UserProfile: React.FC = () =&gt; {<br>  const [user, setUser] = useState&lt;User | null&gt;(null);<br>  const [posts, setPosts] = useState&lt;Post[]&gt;([]);<br>  const [error, setError] = useState&lt;string | null&gt;(null);<br><br>  useEffect(() =&gt; {<br>    const fetchUserData = async () =&gt; {<br>      try {<br>        const response = await fetch(&#39;https://jsonplaceholder.typicode.com/users/1&#39;);<br>        if (!response.ok) {<br>          throw new Error(&#39;Failed to fetch user data&#39;);<br>        }<br>        const data = await response.json();<br>        setUser(data);<br>      } catch (error) {<br>        setError(&#39;Failed to fetch user data&#39;);<br>      }<br>    };<br><br>    const fetchUserPosts = async () =&gt; {<br>      try {<br>        const response = await fetch(&#39;https://jsonplaceholder.typicode.com/posts?userId=1&#39;);<br>        if (!response.ok) {<br>          throw new Error(&#39;Failed to fetch user posts&#39;);<br>        }<br>        const data = await response.json();<br>        setPosts(data);<br>      } catch (error) {<br>        setError(&#39;Failed to fetch user posts&#39;);<br>      }<br>    };<br><br>    fetchUserData();<br>    fetchUserPosts();<br>  }, []);<br><br>  if (error) {<br>    return &lt;div&gt;{error}&lt;/div&gt;;<br>  }<br><br>  if (!user) {<br>    return &lt;div&gt;Loading...&lt;/div&gt;;<br>  }<br><br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;{user.name}&lt;/h1&gt;<br>      &lt;p&gt;{user.email}&lt;/p&gt;<br>      &lt;h2&gt;User Posts&lt;/h2&gt;<br>      &lt;ul&gt;<br>        {posts.map(post =&gt; (<br>          &lt;li key={post.id}&gt;<br>            &lt;h3&gt;{post.title}&lt;/h3&gt;<br>            &lt;p&gt;{post.body}&lt;/p&gt;<br>          &lt;/li&gt;<br>        ))}<br>      &lt;/ul&gt;<br>    &lt;/div&gt;<br>  );<br>};<br><br>export default UserProfile;</pre><p>Now this component fetches user as well as the posts.</p><p>Let’s see how we can mock multiple fetch responses. 😎</p><pre>import { render, screen, waitFor } from &#39;@testing-library/react&#39;;<br>import UserProfile from &#39;./UserProfile&#39;;<br><br>describe(&#39;UserProfile Component&#39;, () =&gt; {<br>  beforeEach(() =&gt; {<br>    jest.mocked(window.fetch).mockImplementation((input, _init) =&gt; {<br>      if (input.toString().includes(&#39;/users/1&#39;)) {<br>        return Promise.resolve({<br>          ok: true,<br>          json: () =&gt; Promise.resolve({<br>            name: &#39;Leanne Graham&#39;,<br>            email: &#39;leanne@example.com&#39;,<br>          }),<br>        } as Response);<br>      }<br><br>      if (input.toString().includes(&#39;/posts?userId=1&#39;)) {<br>        return Promise.resolve({<br>          ok: true,<br>          json: () =&gt; Promise.resolve([<br>            { id: 1, title: &#39;Post Title 1&#39;, body: &#39;Post body 1&#39; },<br>            { id: 2, title: &#39;Post Title 2&#39;, body: &#39;Post body 2&#39; },<br>          ]),<br>        } as Response);<br>      }<br><br>      return Promise.reject(new Error(&#39;Unexpected fetch call&#39;));<br>    });<br>  });<br><br>  afterEach(() =&gt; {<br>    jest.restoreAllMocks();<br>  });<br><br>  it(&#39;displays loading initially&#39;, () =&gt; {<br>    render(&lt;UserProfile /&gt;);<br>    expect(screen.getByText(/loading/i)).toBeInTheDocument();<br>  });<br><br>  it(&#39;displays user data and posts after fetch&#39;, async () =&gt; {<br>    render(&lt;UserProfile /&gt;);<br>    await waitFor(() =&gt; expect(screen.getByText(&#39;Leanne Graham&#39;)).toBeInTheDocument());<br>    expect(screen.getByText(&#39;leanne@example.com&#39;)).toBeInTheDocument();<br>    expect(screen.getByText(&#39;Post Title 1&#39;)).toBeInTheDocument();<br>    expect(screen.getByText(&#39;Post body 1&#39;)).toBeInTheDocument();<br>    expect(screen.getByText(&#39;Post Title 2&#39;)).toBeInTheDocument();<br>    expect(screen.getByText(&#39;Post body 2&#39;)).toBeInTheDocument();<br>  });<br><br>  it(&#39;handles fetch errors gracefully&#39;, async () =&gt; {<br>    jest.mocked(window.fetch).mockImplementation(() =&gt; Promise.reject(new Error(&#39;Fetch error&#39;)));<br><br>    render(&lt;UserProfile /&gt;);<br>    await waitFor(() =&gt; {<br>      expect(window.fetch).toHaveBeenCalled();<br>      expect(screen.getByText(/loading/i)).toBeInTheDocument();<br>    });<br><br>    await waitFor(() =&gt; expect(screen.getByText(/failed to fetch user data/i)).toBeInTheDocument());<br>    expect(consoleErrorSpy).toHaveBeenCalledWith(&#39;Error fetching user data:&#39;, expect.any(Error));<br>  });<br>});</pre><p>and that’s it! We map the responses to the API urls and return the relevant mock response.</p><p>Hope this was helpful.</p><p>See you in the next part of this series <a href="https://medium.com/@sinha.richa08/jest-series-part-2-testing-a-react-custom-hook-cb93244f64f2">Jest Series Part 2 — Testing a react custom hook</a> , where I will talk about testing a React custom hook. Ciao!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b430da0f0d16" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unlocking Success: How UX Design Systems Transform Product Development]]></title>
            <link>https://medium.com/@sinha.richa08/unlocking-success-how-ux-design-systems-transform-product-development-de5976c4a8da?source=rss-c1366fe51c1c------2</link>
            <guid isPermaLink="false">https://medium.com/p/de5976c4a8da</guid>
            <category><![CDATA[product-development]]></category>
            <category><![CDATA[system-ux-design]]></category>
            <category><![CDATA[team-collaboration]]></category>
            <category><![CDATA[efficient-design]]></category>
            <category><![CDATA[brand-consistency]]></category>
            <dc:creator><![CDATA[Richa Sinha]]></dc:creator>
            <pubDate>Wed, 07 May 2025 14:59:08 GMT</pubDate>
            <atom:updated>2025-05-07T14:59:08.053Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4_HuU6LUAepzBQlT" /><figcaption>Photo by <a href="https://unsplash.com/@ka_idris?utm_source=medium&amp;utm_medium=referral">Kam Idris</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In the fast-paced world of digital product development, creating a seamless user experience is more critical than ever. As teams grow and projects scale, maintaining consistency across multiple platforms and interfaces can become increasingly challenging. This is where UX design systems come into play, acting as a cornerstone for efficient and cohesive product development.</p><h3>What is a UX Design System?</h3><p>A UX design system is a comprehensive set of guidelines, components, and tools that help teams create consistent and high-quality user experiences. It typically includes design principles, UI components, brand guidelines, and documentation that serve as a single source of truth for designers, developers, and stakeholders.</p><h3>The Importance of UX Design Systems</h3><h3>1. Consistency Across Products</h3><p>One of the primary benefits of a design system is ensuring consistency across all user interfaces. Consistent design elements like buttons, typography, and color schemes help users navigate products intuitively, enhancing their overall experience. This consistency builds trust and familiarity, which are crucial for user retention.</p><h3>2. Efficiency and Speed</h3><p>Design systems streamline the design and development process by providing reusable components and templates. This reduces the time spent on repetitive tasks and allows teams to focus on innovation and problem-solving. With a design system in place, new team members can quickly get up to speed, reducing onboarding time and accelerating project timelines.</p><h3>3. Collaboration and Communication</h3><p>A well-documented design system fosters better collaboration between designers, developers, and other stakeholders. It serves as a common language that everyone can understand, reducing miscommunication and ensuring that everyone is aligned with the product vision. This collaborative environment leads to more effective problem-solving and creative solutions.</p><h3>4. Quality and Innovation</h3><p>By establishing a solid foundation of design principles and components, teams can focus on delivering high-quality user experiences. Design systems encourage innovation by freeing up time and resources that would otherwise be spent on maintaining consistency. This enables teams to experiment and push the boundaries of design, leading to more engaging and impactful products.</p><h3>“Why bother with a design system when tools like MUI and Ant Design have us covered?”</h3><p>While libraries like Material-UI (MUI) provide a fantastic set of pre-built components and styles, a design system offers additional benefits tailored specifically to your product and brand. Here’s why a product still needs a design system even when using libraries like MUI:</p><h3>1. Brand Consistency</h3><p>While component libraries offer a standardised set of components, a design system ensures that these components align with your unique brand identity. It incorporates brand-specific elements like color palettes, typography, and iconography, ensuring that every aspect of your product reflects your brand consistently across all platforms.</p><h3>2. Custom Components</h3><p>A design system allows you to extend or modify library components to better fit your product’s needs. A design system helps manage these customisations systematically.</p><h3>3. Unified Guidelines</h3><p>A design system encompasses more than just UI components; it includes design principles, accessibility standards, and interaction patterns that guide the overall user experience. These guidelines ensure that everyone on your team, from designers to developers, is aligned with the product vision and user experience goals.</p><h3>4. Cross-Functional Collaboration</h3><p>Design systems serve as a common language between cross-functional teams, facilitating better collaboration and communication.</p><h3>5. Scalability and Flexibility</h3><p>As your product evolves, a design system provides the flexibility to scale and adapt to new requirements. It offers a structured approach to incorporating new features and interfaces, ensuring consistency and quality even as your product grows.</p><h3>6. Enhanced User Experience</h3><p>Ultimately, a design system is tailored to enhance the user experience specific to your product. This user-centric approach leads to more engaging and effective products.In today’s fast-paced world, having a UX design system isn’t just a bonus — it’s a game-changer. It keeps your brand consistent, your team efficient, and your product ready to scale, all while sparking creativity and teamwork. As we dive deeper into the digital age, these systems are set to become the backbone of standout product development.”</p><p>In today’s fast-paced world, having a UX design system isn’t just a bonus — it’s a game-changer.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de5976c4a8da" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>