Skip to content

Comments

test(preact-query/useQuery): add test for not fetching during restoring period when 'isRestoring' is true#10180

Open
sukvvon wants to merge 1 commit intoTanStack:mainfrom
sukvvon:test/preact-query-useBaseQuery-isRestoring
Open

test(preact-query/useQuery): add test for not fetching during restoring period when 'isRestoring' is true#10180
sukvvon wants to merge 1 commit intoTanStack:mainfrom
sukvvon:test/preact-query-useBaseQuery-isRestoring

Conversation

@sukvvon
Copy link
Contributor

@sukvvon sukvvon commented Feb 24, 2026

🎯 Changes

Add a test to verify that useQuery does not fetch during the restoring period when isRestoring is true.

This improves useBaseQuery.ts branch coverage (68.96% → 72.41%) by covering the isRestoring branch at line 70.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Tests
    • Added test to verify query behavior during application restoration. Confirms data fetching is deferred while restoration is active, with proper state management for query status, fetch status, and data handling during the initialization window.

@changeset-bot
Copy link

changeset-bot bot commented Feb 24, 2026

⚠️ No Changeset found

Latest commit: 52d78d2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 24, 2026

📝 Walkthrough

Walkthrough

A new test is added to the preact-query test suite that verifies query fetching does not occur during the restoration period when isRestoring is true. The test uses IsRestoringProvider, simulates the restoration duration with timer advancement, and asserts that queryFn remains unevoked while status stays pending.

Changes

Cohort / File(s) Summary
Test Addition
packages/preact-query/src/__tests__/useQuery.test.tsx
New test verifies that query fetching is prevented during the restoration period (when isRestoring is true), confirming that queryFn is not called and fetch status remains idle until after restoration completes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • feat: Preact Adapter #9935: Introduced the IsRestoringProvider that this new test directly uses to verify restoration behavior in the preact-query adapter.

Suggested labels

package: preact-query

Suggested reviewers

  • TkDodo
  • manudeli

Poem

🐰 A rabbit pauses, patient and still,
Testing that queries won't fetch by their will,
While restoring state guards the sacred repose—
No hasty requests 'til the restoration's close! 🕐✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding a test for preventing fetches during the restoring period when isRestoring is true.
Description check ✅ Passed The pull request description matches the required template with all sections completed: Changes section describes the test and coverage improvement, Checklist items are checked, and Release Impact is properly marked as dev-only.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link

nx-cloud bot commented Feb 24, 2026

View your CI Pipeline Execution ↗ for commit 52d78d2

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 1m 11s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-24 06:43:43 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 24, 2026

More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@10180

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@10180

@tanstack/preact-query

npm i https://pkg.pr.new/@tanstack/preact-query@10180

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@10180

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@10180

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@10180

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@10180

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@10180

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@10180

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@10180

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@10180

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@10180

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@10180

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@10180

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@10180

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@10180

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@10180

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@10180

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@10180

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@10180

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@10180

commit: 52d78d2

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/preact-query/src/__tests__/useQuery.test.tsx (1)

6787-6828: LGTM — consider extending with a post-restoration assertion

The test is correctly structured: IsRestoringProvider value={true} suppresses the fetch, the two-phase timer check (0 ms and 11 ms — past the 10 ms sleep) is a solid correctness signal, and queryFn call-count assertions at each checkpoint make the expectation unambiguous.

One optional improvement: the test title says "for the duration of the restoring period," but isRestoring is never transitioned back to false, so the end of that period goes uncovered. Adding a state flip and asserting that queryFn is eventually called (and status reaches 'success') would turn this into a full lifecycle test and provide stronger coverage of the useBaseQuery branch at line 70.

  const rendered = renderWithClient(
    queryClient,
-   <IsRestoringProvider value={true}>
-     <Page />
-   </IsRestoringProvider>,
+   <IsRestoringProvider value={isRestoring}>
+     <Page />
+   </IsRestoringProvider>,
  )

Where isRestoring is a reactive signal (e.g., a signal/state variable) that starts as true and is set to false after the initial assertions.

Based on learnings, the .then() pattern used for the queryFn (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.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eb7dca5 and 52d78d2.

📒 Files selected for processing (1)
  • packages/preact-query/src/__tests__/useQuery.test.tsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant