test(preact-query/useQuery): add test for not fetching during restoring period when 'isRestoring' is true#10180
Conversation
…ng period when 'isRestoring' is true
|
📝 WalkthroughWalkthroughA new test is added to the preact-query test suite that verifies query fetching does not occur during the restoration period when 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)
Comment |
|
View your CI Pipeline Execution ↗ for commit 52d78d2
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/preact-query/src/__tests__/useQuery.test.tsx (1)
6787-6828: LGTM — consider extending with a post-restoration assertionThe test is correctly structured:
IsRestoringProvider value={true}suppresses the fetch, the two-phase timer check (0 ms and 11 ms — past the 10 mssleep) is a solid correctness signal, andqueryFncall-count assertions at each checkpoint make the expectation unambiguous.One optional improvement: the test title says "for the duration of the restoring period," but
isRestoringis never transitioned back tofalse, so the end of that period goes uncovered. Adding a state flip and asserting thatqueryFnis eventually called (and status reaches'success') would turn this into a full lifecycle test and provide stronger coverage of theuseBaseQuerybranch at line 70.const rendered = renderWithClient( queryClient, - <IsRestoringProvider value={true}> - <Page /> - </IsRestoringProvider>, + <IsRestoringProvider value={isRestoring}> + <Page /> + </IsRestoringProvider>, )Where
isRestoringis a reactive signal (e.g., a signal/state variable) that starts astrueand is set tofalseafter the initial assertions.Based on learnings, the
.then()pattern used for thequeryFn(which has no side effects) is the idiomatic form for this test suite, and the implementation is consistent with that convention.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/preact-query/src/__tests__/useQuery.test.tsx` around lines 6787 - 6828, The test currently never flips IsRestoringProvider back to false so it only asserts suppression; update the test to simulate the end of the restoring period by changing the provider value to false (e.g., render with a reactive state/signal for IsRestoringProvider and set it to false after the initial assertions), then advance timers (vi.advanceTimersByTimeAsync) enough for the queryFn (the mocked function used in Page/useQuery) to run and add assertions that queryFn was called and that the rendered status reaches 'success' and fetchStatus updates accordingly; locate the change around the existing IsRestoringProvider usage, the Page component, and the queryFn/mock to implement this transition and final assertions.
🤖 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__/useQuery.test.tsx`:
- Around line 6787-6828: The test currently never flips IsRestoringProvider back
to false so it only asserts suppression; update the test to simulate the end of
the restoring period by changing the provider value to false (e.g., render with
a reactive state/signal for IsRestoringProvider and set it to false after the
initial assertions), then advance timers (vi.advanceTimersByTimeAsync) enough
for the queryFn (the mocked function used in Page/useQuery) to run and add
assertions that queryFn was called and that the rendered status reaches
'success' and fetchStatus updates accordingly; locate the change around the
existing IsRestoringProvider usage, the Page component, and the queryFn/mock to
implement this transition and final assertions.
🎯 Changes
Add a test to verify that
useQuerydoes not fetch during the restoring period whenisRestoringistrue.This improves
useBaseQuery.tsbranch coverage (68.96% → 72.41%) by covering theisRestoringbranch at line 70.✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit