test(preact-query/useSuspenseQueries): align cached data test with react-query to verify background refetch#10195
Conversation
…act-query to verify background refetch
|
|
View your CI Pipeline Execution ↗ for commit da9191a
☁️ Nx Cloud last updated this comment at |
📝 WalkthroughWalkthroughThis change modifies the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
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)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/preact-query/src/__tests__/useSuspenseQueries.test.tsx (1)
870-874: Consider replacing timing literals with local named constants.The test is clear, but extracting
2000/1000into local constants would reduce drift risk betweenqueryFndurations and timer advances.♻️ Suggested refactor
it('should only suspend queries that are pending when some queries already have data', async () => { const key1 = queryKey() const key2 = queryKey() + const key1FetchMs = 2000 + const key2FetchMs = 1000 queryClient.setQueryData(key1, 'cached') function Page() { const [result1, result2] = useSuspenseQueries({ queries: [ { queryKey: key1, - queryFn: () => sleep(2000).then(() => 'data1'), + queryFn: () => sleep(key1FetchMs).then(() => 'data1'), }, { queryKey: key2, - queryFn: () => sleep(1000).then(() => 'data2'), + queryFn: () => sleep(key2FetchMs).then(() => 'data2'), }, ], }) @@ - await vi.advanceTimersByTimeAsync(1000) + await vi.advanceTimersByTimeAsync(key2FetchMs) @@ - await vi.advanceTimersByTimeAsync(1000) + await vi.advanceTimersByTimeAsync(key1FetchMs - key2FetchMs) @@ - await vi.advanceTimersByTimeAsync(2000) + await vi.advanceTimersByTimeAsync(key1FetchMs)Also applies to: 897-907
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/preact-query/src/__tests__/useSuspenseQueries.test.tsx` around lines 870 - 874, Extract the numeric time literals used in the test into named local constants (e.g., const DURATION_LONG = 2000, const DURATION_SHORT = 1000) and use those constants in the queryFn sleep calls and any corresponding timer advances/assertions; update the two query objects (the ones with queryFn: () => sleep(2000)... and queryFn: () => sleep(1000)...) to call sleep(DURATION_LONG) / sleep(DURATION_SHORT) and replace matching advanceTimersByTime or wait calls elsewhere in useSuspenseQueries.test.tsx (also apply the same refactor to the similar block around lines 897-907) so durations stay consistent and maintainable.
🤖 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/preact-query/src/__tests__/useSuspenseQueries.test.tsx`:
- Around line 870-874: Extract the numeric time literals used in the test into
named local constants (e.g., const DURATION_LONG = 2000, const DURATION_SHORT =
1000) and use those constants in the queryFn sleep calls and any corresponding
timer advances/assertions; update the two query objects (the ones with queryFn:
() => sleep(2000)... and queryFn: () => sleep(1000)...) to call
sleep(DURATION_LONG) / sleep(DURATION_SHORT) and replace matching
advanceTimersByTime or wait calls elsewhere in useSuspenseQueries.test.tsx (also
apply the same refactor to the similar block around lines 897-907) so durations
stay consistent and maintainable.
🎯 Changes
Align the
should only suspend queries that are pending when some already have cached datatest in preact-query with the react-query version (#10126).Previously, the preact test used the same
QUERY_DURATIONfor both queries and only verified the initial suspend/resolve. The updated test uses different durations for each query (matching react-query) and verifies that the background refetch completes and updateskey1from'cached'to'data1'.✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit