Skip to content

test(query-core): assert exact values instead of loose matchers in remaining tests#11093

Open
reizam wants to merge 2 commits into
TanStack:mainfrom
reizam:test/query-core-exact-assertions
Open

test(query-core): assert exact values instead of loose matchers in remaining tests#11093
reizam wants to merge 2 commits into
TanStack:mainfrom
reizam:test/query-core-exact-assertions

Conversation

@reizam

@reizam reizam commented Jul 21, 2026

Copy link
Copy Markdown

🎯 Changes

Continues the recent test-quality series (e.g. #11057, #11043, #11048) by converting the remaining toBeTruthy() / toBeFalsy() / toBeDefined() assertions in query-core tests to exact assertions:

  • queryCache.find(...) presence checks now assert the exact cached value (?.state.data) or status (?.state.status) produced at that point of the test, and absence checks use toBeUndefined() instead of toBeFalsy()/not.toBeDefined().
  • isPaused boolean check uses toBe(true).
  • error?.message.includes(...) + toBeTruthy() becomes toContain(...) for a precise failure message.
  • Cache event queries in queryCache.test.tsx now assert reference identity against the cached query (toBe(cachedQuery)) instead of mere existence.
  • Three redundant existence checks (expect(state).toBeTruthy() / expect(args).toBeDefined()) were removed where the neighboring exact assertions already fail on an undefined object.

After this, grep -rE 'toBeTruthy\(\)|toBeFalsy\(\)|toBeDefined\(\)' packages/query-core/src returns no matches.

✅ Checklist

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

Local verification detail: vitest run in packages/query-core — 24 files, 554 tests passed, no type errors; test:eslint and prettier clean; test:types green on all six TypeScript versions (5.4 → 5.9).

🚀 Release Impact

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

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Query-core assertion tightening

Layer / File(s) Summary
Hydration and cache result assertions
packages/query-core/src/__tests__/hydration.test.tsx, packages/query-core/src/__tests__/queriesObserver.test.tsx, packages/query-core/src/__tests__/queryCache.test.tsx
Hydration tests assert exact data and exclusion of unsuccessful queries; cache tests verify query identity and prefetched data.
Query lifecycle state assertions
packages/query-core/src/__tests__/query.test.tsx
Garbage-collection tests assert specific query states and retained data, while the serialization error matcher uses toContain.
Query client lifecycle assertions
packages/query-core/src/__tests__/queryClient.test.tsx
Prefetch, removal, reset, and paused-mutation tests assert explicit data, state, and cache outcomes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: sukvvon, tkdodo

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly matches the PR’s main change: tightening query-core tests to exact assertions instead of loose matchers.
Description check ✅ Passed The description follows the required template and includes changes, checklist, and release impact with relevant details.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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