All Questions
Tagged with react-query jestjs
37
questions
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 ...
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 ...
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", () => ...
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,...
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 { ...
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 ...
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-...
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 ...
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 ...
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});
...
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 ...
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 } ...
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 ...
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 = () => {
...
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(`${...