Skip to content

test(query-core/queryObserver): add tests for 'refetchOnWindowFocus' as a function in 'shouldFetchOnWindowFocus'#10898

Merged
sukvvon merged 1 commit into
mainfrom
test/query-core-query-observer-should-fetch-on-window-focus-function
Jun 7, 2026
Merged

test(query-core/queryObserver): add tests for 'refetchOnWindowFocus' as a function in 'shouldFetchOnWindowFocus'#10898
sukvvon merged 1 commit into
mainfrom
test/query-core-query-observer-should-fetch-on-window-focus-function

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented Jun 7, 2026

🎯 Changes

Add tests covering refetchOnWindowFocus as a function in shouldFetchOnWindowFocus.

The existing tests only cover the value forms (true, false, "always"), which all take the : field branch of typeof field === "function" ? field(query) : field. These add the function forms so the field(query) branch is covered.

Each function is a vi.fn and asserts it is called with the query (toHaveBeenCalledWith), so the function-call path and the query argument are both verified:

  • a function returning true
  • a function returning false
  • a function returning "always", kept fresh via staleTime: Infinity so only the "always" path can make it true

✅ 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).

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 7, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

Adds three tests to QueryObserver.shouldFetchOnWindowFocus() verifying behavior when refetchOnWindowFocus is a function returning true, false, or "always", and that the callback is called with the query cache entry.

Changes

Window focus callback behavior tests

Layer / File(s) Summary
shouldFetchOnWindowFocus() callback behavior tests
packages/query-core/src/__tests__/queryObserver.test.tsx
Three new test cases verify QueryObserver.shouldFetchOnWindowFocus() when refetchOnWindowFocus is a function: returning true yields true, returning false yields false, and returning "always" yields true even for fresh queries (staleTime: Infinity); each test also asserts the callback is invoked with the query cache entry from queryClient.getQueryCache().find({ queryKey }).

Sequence Diagram(s)

sequenceDiagram
  participant Test
  participant QueryObserver
  participant QueryClient
  participant QueryCache
  Test->>QueryObserver: call shouldFetchOnWindowFocus()
  QueryObserver->>QueryClient: getQueryCache()
  QueryClient->>QueryCache: find({ queryKey })
  QueryCache-->>QueryObserver: query cache entry
  QueryObserver-->>Test: boolean decision (true/false)
Loading

Possibly related PRs

  • TanStack/query#10897: Yes—both PRs add/adjust queryObserver.test.tsx window-focus refetch test cases around refetchOnWindowFocus callback behavior in QueryObserver.shouldFetchOnWindowFocus(), with overlapping coverage of the same logic.
  • TanStack/query#10896: The main PR adds additional QueryObserver.shouldFetchOnWindowFocus tests for refetchOnWindowFocus callback values (true, false, and "always") in the same queryObserver.test.tsx, directly overlapping with the retrieved PR’s new "always" test case.
  • TanStack/query#10889: Both PRs modify packages/query-core/src/__tests__/queryObserver.test.tsx to extend/reshape QueryObserver.shouldFetchOnWindowFocus() test coverage around refetchOnWindowFocus values (booleans vs callback outcomes).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A little rabbit hops to run the test,
Callback returns guide whether focus fetches best.
True springs a fetch, false lets it be,
"Always" wakes even a fresh query—whee!
Tests nibble crumbs of cache for certainty.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding tests for 'refetchOnWindowFocus' as a function in 'shouldFetchOnWindowFocus', which directly matches the PR's purpose of covering the function form of this option.
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.
Description check ✅ Passed The pull request description comprehensively addresses all required template sections with clear explanations of changes, completed checklist items, and proper release impact designation.

✏️ 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-should-fetch-on-window-focus-function

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

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Jun 7, 2026

View your CI Pipeline Execution ↗ for commit 2a90a52

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

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


☁️ Nx Cloud last updated this comment at 2026-06-07 04:28:53 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@10898

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: e6644a8

@sukvvon sukvvon force-pushed the test/query-core-query-observer-should-fetch-on-window-focus-function branch from 2a90a52 to e6644a8 Compare June 7, 2026 04:22
@sukvvon sukvvon self-assigned this Jun 7, 2026
@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 413fdc5 into main Jun 7, 2026
9 checks passed
@sukvvon sukvvon deleted the test/query-core-query-observer-should-fetch-on-window-focus-function branch June 7, 2026 04:32
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