Skip to content

test(query-core/queryObserver): add test for 'refetchInterval' as a function refetching at the returned interval#10899

Merged
sukvvon merged 1 commit into
mainfrom
test/query-core-query-observer-refetch-interval-function
Jun 7, 2026
Merged

test(query-core/queryObserver): add test for 'refetchInterval' as a function refetching at the returned interval#10899
sukvvon merged 1 commit into
mainfrom
test/query-core-query-observer-refetch-interval-function

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented Jun 7, 2026

🎯 Changes

Adds a test in queryObserver.test.tsx covering the function form of refetchInterval.

Existing refetchInterval tests only use the number form (refetchInterval: 10). This test verifies that when refetchInterval is a function, the returned interval is actually applied, asserting the query refetches at that interval via the count side effect.

This covers the previously uncovered branch in #computeRefetchInterval where refetchInterval is called as a function.

✅ 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
    • Enhanced test coverage for the query observer's refetchInterval functionality to verify support for function-based interval values.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 7, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 239a76ed-770b-4e3d-a016-9f144f3344c4

📥 Commits

Reviewing files that changed from the base of the PR and between 413fdc5 and 1eaac1d.

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

📝 Walkthrough

Walkthrough

This PR adds a test case to queryObserver.test.tsx that verifies QueryObserver correctly handles refetchInterval when provided as a function. The test confirms the observer performs an initial fetch and then refetches at intervals determined by the function's return value using fake timers.

Changes

Query refetchInterval function test

Layer / File(s) Summary
Test refetchInterval as a function
packages/query-core/src/__tests__/queryObserver.test.tsx
New test verifies that when refetchInterval is a function returning 10, QueryObserver performs an initial fetch and refetches after advancing timers by 10, with fetch count assertions and cleanup validation.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A function refetches the query with care,
Timers advance, data flows through the air,
Tests confirm intervals work just right,
One small assertion, shining bright! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a test for refetchInterval as a function with verification of refetch timing.
Description check ✅ Passed The description follows the template structure with completed 'Changes' and 'Checklist' sections, properly marked Release Impact as dev-only, and provides clear context about the test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/query-core-query-observer-refetch-interval-function

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

@sukvvon sukvvon self-assigned this Jun 7, 2026
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Jun 7, 2026

View your CI Pipeline Execution ↗ for commit 1eaac1d

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 2m 16s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-06-07 07:00:14 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 7, 2026

🚀 Changeset Version Preview

No changeset entries found. Merging this PR will not cause a version bump for any packages.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 7, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

npm i https://pkg.pr.new/@tanstack/lit-query@10899

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@10899

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 1eaac1d

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 7, 2026

size-limit report 📦

Path Size
react full 12.11 KB (0%)
react minimal 9.08 KB (0%)

@sukvvon sukvvon merged commit 84cbbdb into main Jun 7, 2026
11 of 12 checks passed
@sukvvon sukvvon deleted the test/query-core-query-observer-refetch-interval-function branch June 7, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant