Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
1 vote
1 answer
46 views

What should I do to pass this React custom hook test?

"I'm new to testing. I've been attempting to test my custom hook, but despite encountering numerous errors, I still haven't been able to pass the test. The hook simply utilizes the useQuery hook ...
Douglas de Brito's user avatar
1 vote
1 answer
61 views

How to mock only the data except other information (isLoading, isError, etc.) returned from custom hook using useQuery?

Environment Next.js v14 Pages Router jest v29.7 @tanstack/react-query v5.36.0 Overview There is a custom hook called useUserInfo that wraps useQuery from tanstack-query, and It fetches user ...
pop's user avatar
  • 119
0 votes
0 answers
33 views

Jest test error [Error: No QueryClient set, use QueryClientProvider to set one]

I keep getting error [Error: No QueryClient set, use QueryClientProvider to set one] though I have wrapped my test in a QueryClientProvider. What do I do wrong. describe("Selector", () => ...
ComCool's user avatar
  • 1,043
0 votes
0 answers
21 views

How to test conditional rendering component with useQuery result data?

I am testing my React component. In my component, I use useQuery for category items. And if there is a data (category array), select element is rendered. Below is my source. const { data: categories,...
kmyz's user avatar
  • 9
0 votes
0 answers
310 views

Result is always null in renderHook using React query and RTL

I am writing a test case for a component. import { render, screen, waitFor, renderHook } from "@testing-library/react"; import { MemoryRouter } from "react-router-dom"; import { ...
ganesh kaspate's user avatar
0 votes
0 answers
99 views

React Testing Library: useMutation from React Query Not Called in Formik onSubmit

I'm having an issue with testing a React component that uses Formik for form handling and React Query's useMutation for data submission. Despite setting up mocks and simulating a form submission, the ...
tcode's user avatar
  • 1
1 vote
0 answers
86 views

How test a function that return JSX.Element and contains API request?

I have a custom function that show a user's card (returns JSX.Element) when the pointer is over the user's name. This component request user information using React Query, which I use for data-...
Danil Parkhomenko's user avatar
3 votes
1 answer
1k views

React Query Test with MSW - renderHook result always returns null

I am trying to test my react query hook using msw but renderHook's result's current value is always null. Why? Note: the reason fetch does not include a URL is because this is a Rails Propshaft app ...
asus's user avatar
  • 1,677
0 votes
0 answers
1k views

How do I do a unit test of a component with a React Query custom hook?

I am practicing because I am interested in the React Testing Library with Jest. I'm writing a unit test of the component, but I keep getting errors, so I'd like to ask you a question. First, I am ...
김정수's user avatar
  • 781
1 vote
0 answers
805 views

Jest spyOn useMutation with mocked data

it('should execute custom onSuccess callback', async () => { const onSuccess = jest.fn(); const spyQuery = jest.spyOn(ReactQuery, 'useMutation').mockReturnValue({mutate: onSuccess}); ...
shivetay's user avatar
  • 354
0 votes
2 answers
628 views

How can I test two different GET queries in the same React custom hook using react testing library and react-hooks?

I'm using a custom react hook to perform two GET operations using react query. The API is in a separate module and uses both getTestByUid() and getTestStatuses() inside useQuery. // TestHook.js import ...
Tony96's user avatar
  • 33
1 vote
2 answers
4k views

Testing simple component that uses React Query

How would I write a passing test for the following? Where getLifestages is a working get API call that returns an array such as: [{_id: 1, title: 'School'},{_id: 2, title: 'Work'}] import { useQuery } ...
abbyabby's user avatar
2 votes
0 answers
440 views

Testing multiple usequeries in one component only considers one query

I am using React Query along with json-server to mock my API. I am trying to test my Home page which has a list of todos and one pined todo. The mock api will return 9 todos and 1 pined todo when ...
Ozeus's user avatar
  • 181
2 votes
1 answer
2k views

Unit testing onSuccess for a react query call

I have a component that looks like this: <TestComponent refetch={fn} /> Within TestComponent, I have a save button that fires off a mutation: const handleSaveClick = () => { ...
syn's user avatar
  • 21
0 votes
1 answer
237 views

Implement query to component in Jest with ReactQuery

I would like to test my component if it renders after receiving data from query. Fetch function: const fetchWeather = async (lat: number, lon: number) => { const response = await fetch(`${...
strB's user avatar
  • 31

15 30 50 per page