Skip to content

test(solid-query): assert exact values instead of loose matchers#11105

Open
reizam wants to merge 1 commit into
TanStack:mainfrom
reizam:test/solid-query-exact-assertions
Open

test(solid-query): assert exact values instead of loose matchers#11105
reizam wants to merge 1 commit into
TanStack:mainfrom
reizam:test/solid-query-exact-assertions

Conversation

@reizam

@reizam reizam commented Jul 22, 2026

Copy link
Copy Markdown

🎯 Changes

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

  • QueryClientProvider — cache presence checks now assert the exact cached value (?.state.data) produced by the test's queryFn, and the cross-cache absence checks in the partitioning test use toBeUndefined() instead of not.toBeDefined(). One redundant existence check was removed where the next line already asserts ?.options.gcTime on the same query (it fails on undefined either way).
  • suspense — the cache absence check before mount uses toBeUndefined() instead of toBeFalsy().
  • useQuery — after the first fetch in the client-switch test, the presence check on queryClient1's cache now asserts the exact cached value.
  • mutationOptions — removed expect(lastSnapshot[1]).toBeFalsy(): the preceding expect(lastSnapshot.length).toEqual(1) already guarantees there is no second entry.

One toBeDefined() is intentionally left in place: in useQuery"should refetch query when queryClient changes", tightening the queryClient2 cache check to ?.state.data fails. After setClient(queryClient2), the second queryFn call actually lands in queryClient1's cache (its dataUpdateCount goes to 2) while the entry in queryClient2's cache stays status: 'pending' / fetchStatus: 'idle' and never fetches. This looks like an observer re-subscription ordering issue in useBaseQuery (in the on(client, ...) computed, createClientSubscriber() is called before setObserver(newObserver), so the subscription attaches to the old observer). I'd rather report and fix that separately than encode the current behavior into an exact assertion here.

After this, grep -rE 'toBeTruthy\(\)|toBeFalsy\(\)|toBeDefined\(\)' packages/solid-query/src only matches the site described above.

✅ Checklist

Local verification detail: vitest run on the four edited files — 162 tests passed, no type errors; test:eslint and prettier clean; full-suite failure set identical to main in the same environment.

🚀 Release Impact

  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Tests
    • Strengthened cache validation to confirm stored query data and correct separation across caches.
    • Improved mutation state assertions to verify returned successful data.
    • Clarified unmount behavior by checking that removed queries are absent.
    • Tightened refetch validation to confirm expected cached results.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

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: 8087fcbe-ade6-42f8-b190-ad0704c60128

📥 Commits

Reviewing files that changed from the base of the PR and between 86bb8a6 and cc8615f.

📒 Files selected for processing (4)
  • packages/solid-query/src/__tests__/QueryClientProvider.test.tsx
  • packages/solid-query/src/__tests__/mutationOptions.test.tsx
  • packages/solid-query/src/__tests__/suspense.test.tsx
  • packages/solid-query/src/__tests__/useQuery.test.tsx
💤 Files with no reviewable changes (1)
  • packages/solid-query/src/tests/mutationOptions.test.tsx

📝 Walkthrough

Walkthrough

Tests tighten Solid Query cache and mutation assertions by validating stored data values, cache isolation, explicit undefined results, and filtered mutation output.

Changes

Solid Query test assertions

Layer / File(s) Summary
Query cache state and isolation assertions
packages/solid-query/src/__tests__/QueryClientProvider.test.tsx, packages/solid-query/src/__tests__/useQuery.test.tsx, packages/solid-query/src/__tests__/suspense.test.tsx
Cache tests now verify resolved state.data, partition-specific entries, and explicit undefined results while retaining default-option validation.
Filtered mutation data assertion
packages/solid-query/src/__tests__/mutationOptions.test.tsx
The filtered mutation-state test now verifies the matching mutation’s data is data1.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested reviewers: sukvvon

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: tightening solid-query tests to exact-value assertions.
Description check ✅ Passed The description follows the template and includes changes, checklist, and release-impact sections with the required details.
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.
✨ 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