State Management · Senior · Question 56 of 75
How should components using TanStack Query be set up in tests?
- ✓Correct answer: Create a fresh
QueryClientper test withretry: falseand wrap the component in its provider - 2Share one global client across all tests
- 3Mock
useQueryto return fixed data in every test
Explanation
A shared client leaks cache between tests; retries make failing requests take seconds. Mock the network (MSW) rather than the hook.