How to mock and test Intl.DateTimeFormat in Jest

How to mock and test Intl.DateTimeFormat in Jest

Intl.DateTimeFormat provides powerful functionalities to format dates. This article demonstrates how to mock and test Intl.DateTimeFormat with Jest. Example Consider we have the following function that does…

How to parse a URL query parameters in javascript

How to parse a URL query parameters in javascript

To parse the URL query parameters in Javascript, we can use the URLSearchParams interface, which has some utility functions that allow us to easily parse/build URLs. Examples…

useNavigate may be used only in the context of a component

Jest useNavigate may be used only in the context of a router

While working with Jest and React-Testing-Library, you might encounter the following error: useNavigate() may be used only in the context of a <Router> component There are two…

useNavigate may be used only in the context of a component

useNavigate may be used only in the context of a component

If you’ve ever faced the following error in React: useNavigate() may be used only in the context of a component This error throws in useNavigate hook.  This happens…

How to mock React-Router-Dom hooks in Jest

How to mock React-Router-Dom hooks in Jest

To mock React-Router-Dom hooks in React you need to do the following: Mock the library React-Router-Dom using jest.mock Import non-mocked React-Router-Dom, so that we can use the…

 How To Dynamically load a JavaScript file in React

How To Dynamically load a JavaScript file in React

Introduction Some use cases require loading a specific Javascript script conditionally, this article will demonstrate how to dynamically load a javascript file in React once a particular…

How to change the styles of MUI TextField In React

How to change the styles of MUI TextField In React

MUI library is a great library that offers a comprehensive suite of UI tools that helps ship new features faster. Sometimes we would like to customize the…

Found multiple elements error in React Testing Library

Found multiple elements error in React Testing Library

Introduction While working with React-Testing-Library to test UI components, you might encounter an error like the following: HTML Structure: Here’s an example of the HTML structure that…

How to invalidate query after mutations in React-Query

How to invalidate query after mutations in React-Query

Introduction Query invalidation is an essential part while working with React-Query. Usually, when there is a mutation in the app, there are queries related, and when a…