test(react-query/useSuspenseInfiniteQuery): add test for basic suspend and resolve states#10213
Conversation
…d and resolve states
|
📝 WalkthroughWalkthroughTest setup and lifecycle hooks for fake timers were added, along with expanded imports. A new comprehensive test case verifies state transitions for Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
View your CI Pipeline Execution ↗ for commit b3938b9
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/react-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx (1)
15-21: Consider scoping fake timers to only the test that needs them.Applying
vi.useFakeTimers()inbeforeEachaffects all tests in this describe block, including the existingskipTokentests that don't require fake timers. While this likely won't break them, scoping the timer setup to only the new test improves isolation and makes the test's dependencies explicit.♻️ Suggested refactor: move timer setup into the specific test
describe('useSuspenseInfiniteQuery', () => { - beforeEach(() => { - vi.useFakeTimers() - }) - - afterEach(() => { - vi.useRealTimers() - }) - const queryCache = new QueryCache() const queryClient = new QueryClient({ queryCache }) it('should return the correct states for a successful infinite query', async () => { + vi.useFakeTimers() const key = queryKey() // ... rest of test ... + vi.useRealTimers() })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/react-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx` around lines 15 - 21, The beforeEach/afterEach hooks that call vi.useFakeTimers() and vi.useRealTimers() should be removed from the shared setup and instead applied only inside the specific test that needs fake timers: locate the beforeEach/afterEach in useSuspenseInfiniteQuery.test.tsx and delete them, then add vi.useFakeTimers() at the start of the single test that relies on timers and call vi.useRealTimers() (or restore) at that test's end or in a finally block to ensure cleanup; this scopes fake timers to the test that needs them and avoids affecting other tests such as the skipToken cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/react-query/src/__tests__/useSuspenseInfiniteQuery.test.tsx`:
- Around line 15-21: The beforeEach/afterEach hooks that call vi.useFakeTimers()
and vi.useRealTimers() should be removed from the shared setup and instead
applied only inside the specific test that needs fake timers: locate the
beforeEach/afterEach in useSuspenseInfiniteQuery.test.tsx and delete them, then
add vi.useFakeTimers() at the start of the single test that relies on timers and
call vi.useRealTimers() (or restore) at that test's end or in a finally block to
ensure cleanup; this scopes fake timers to the test that needs them and avoids
affecting other tests such as the skipToken cases.
🎯 Changes
Add a basic suspend → resolve test for
useSuspenseInfiniteQuerythat verifies:pages,pageParams) andstatus: 'success'are correct after resolveThis follows the same pattern as the existing test in
useSuspenseQuery.test.tsx.✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit