Skip to content

test(query-core): replace hardcoded query keys with 'queryKey()' utility#10425

Merged
sukvvon merged 2 commits intomainfrom
test/query-core-replace-hardcoded-keys-with-queryKey
Apr 7, 2026
Merged

test(query-core): replace hardcoded query keys with 'queryKey()' utility#10425
sukvvon merged 2 commits intomainfrom
test/query-core-replace-hardcoded-keys-with-queryKey

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented Apr 7, 2026

🎯 Changes

  • Replace hardcoded query/mutation keys with queryKey() utility from @tanstack/query-test-utils across query-core test files
  • Applied to runtime tests and type tests
  • Files modified: hydration.test.tsx, query.test.tsx, queryCache.test.tsx, queryClient.test-d.tsx, queryObserver.test-d.tsx, utils.test.tsx
  • Rename shadowed queryKey variables to key or filterKey to avoid conflict with imported queryKey utility

✅ 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
    • Updated test suite to use dynamically generated query identifiers instead of hardcoded values across multiple test files, improving test robustness and maintainability.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7162e3a3-af10-4509-8e5e-43356dc53cd5

📥 Commits

Reviewing files that changed from the base of the PR and between 79dee50 and 55dae3b.

📒 Files selected for processing (6)
  • packages/query-core/src/__tests__/hydration.test.tsx
  • packages/query-core/src/__tests__/query.test.tsx
  • packages/query-core/src/__tests__/queryCache.test.tsx
  • packages/query-core/src/__tests__/queryClient.test-d.tsx
  • packages/query-core/src/__tests__/queryObserver.test-d.tsx
  • packages/query-core/src/__tests__/utils.test.tsx

📝 Walkthrough

Walkthrough

This pull request updates test files across the query-core package to replace hard-coded query and mutation key array literals with dynamically generated queryKey() values from @tanstack/query-test-utils. All changes are confined to test files with no modifications to production code or exported/public entities.

Changes

Cohort / File(s) Summary
Hydration and query tests
packages/query-core/src/__tests__/hydration.test.tsx, packages/query-core/src/__tests__/query.test.tsx
Replaced hard-coded query key literals (e.g., ['string'], ['number'], ['key']) with dynamically generated queryKey() values; updated corresponding cache lookups, prefetch calls, and assertions to use generated keys and their queryHash representations.
Query cache and utilities tests
packages/query-core/src/__tests__/queryCache.test.tsx, packages/query-core/src/__tests__/utils.test.tsx
Changed hard-coded key literals (['key1'], ['key2'], ['key3']) to generated keys via queryKey(); adjusted filter configurations and assertion expectations accordingly.
Type definition tests
packages/query-core/src/__tests__/queryClient.test-d.tsx, packages/query-core/src/__tests__/queryObserver.test-d.tsx
Renamed local variables from queryKey to key/filterKey to avoid conflicts with imported queryKey() utility; updated fetchInfiniteQuery and QueryObserver test cases to use generated keys and adjusted type-level assertions for placeholder data callbacks.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 Keys once carved in stone, now dancing free,
Dynamic queryKey() calls—what harmony!
No more ['string'] static, bland and worn,
Test utils spring to life, bright and reborn!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: replacing hardcoded query keys with the queryKey() utility across test files.
Description check ✅ Passed The description includes all required template sections with comprehensive details about changes, files modified, and checklist items completed appropriately.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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-replace-hardcoded-keys-with-queryKey

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

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

nx-cloud bot commented Apr 7, 2026

View your CI Pipeline Execution ↗ for commit 55dae3b

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

☁️ Nx Cloud last updated this comment at 2026-04-07 18:25:59 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 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 Apr 7, 2026

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 55dae3b

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

size-limit report 📦

Path Size
react full 11.98 KB (0%)
react minimal 9.01 KB (0%)

@sukvvon sukvvon merged commit 2e26f14 into main Apr 7, 2026
8 checks passed
@sukvvon sukvvon deleted the test/query-core-replace-hardcoded-keys-with-queryKey branch April 7, 2026 18:28
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