Skip to content

test(svelte-query): extract 'queryClient' creation from Svelte components to test files#10447

Merged
sukvvon merged 3 commits intomainfrom
test/svelte-query-extract-queryClient-to-test-files
Apr 11, 2026
Merged

test(svelte-query): extract 'queryClient' creation from Svelte components to test files#10447
sukvvon merged 3 commits intomainfrom
test/svelte-query-extract-queryClient-to-test-files

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented Apr 11, 2026

🎯 Changes

  • Extract queryClient creation from 14 Svelte test components to test files
    • Components now receive queryClient via $props() and call setQueryClientContext(queryClient)
    • Test files create queryClient in beforeEach and call queryClient.clear() in afterEach
  • Unify queryClient lifecycle management across all svelte-query test files (QueryClientProvider, createInfiniteQuery, createMutation, createQuery, createQueries, useIsFetching, useIsMutating, useMutationState, mutationOptions, HydrationBoundary)
  • Rename let queryClient to let activeClient in createMutation withEffectRoot test to avoid shadowing

✅ 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
    • Improved test component architecture by externalizing QueryClient lifecycle management, enabling better test isolation and reusability across test suites.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 11, 2026

📝 Walkthrough

Walkthrough

Systematic refactoring of svelte-query test files and components to enable dependency injection of QueryClient instances. Test components now accept queryClient as a prop (with QueryClient as a type-only import) instead of instantiating it internally. Corresponding test suites create a shared QueryClient per test in beforeEach, pass it to components via props, and clean it up in afterEach.

Changes

Cohort / File(s) Summary
HydrationBoundary
packages/svelte-query/tests/HydrationBoundary/BaseExample.svelte, packages/svelte-query/tests/HydrationBoundary/HydrationBoundary.svelte.test.ts
Component now receives queryClient as a prop (type-only import); test creates shared client per test lifecycle and passes it to component. Dehydration logic uses separate dehydrateClient instance.
QueryClientProvider
packages/svelte-query/tests/QueryClientProvider/QueryClientProvider.svelte.test.ts
Test introduces shared queryClient per suite, passed to rendered component props; cleanup added via queryClient.clear() in afterEach.
createInfiniteQuery
packages/svelte-query/tests/createInfiniteQuery/BaseExample.svelte, packages/svelte-query/tests/createInfiniteQuery/SelectExample.svelte, packages/svelte-query/tests/createInfiniteQuery/createInfiniteQuery.svelte.test.ts
Both example components refactored to accept queryClient prop (type-only import) instead of internal instantiation; test suite creates shared client and passes it to both examples.
createMutation
packages/svelte-query/tests/createMutation/FailureExample.svelte, packages/svelte-query/tests/createMutation/OnSuccessExample.svelte, packages/svelte-query/tests/createMutation/ResetExample.svelte, packages/svelte-query/tests/createMutation/createMutation.svelte.test.ts
Three example components updated to receive queryClient prop (type-only import); test creates per-test client and passes to all examples. "Observer recreation" test refactored to use mutable activeClient variable instead of reassigning queryClient.
createQueries
packages/svelte-query/tests/createQueries/IsRestoringExample.svelte, packages/svelte-query/tests/createQueries/createQueries.svelte.test.ts
Example component refactored to accept queryClient prop (type-only import); test updated to pass queryClient in render props alongside existing queryFn props.
createQuery
packages/svelte-query/tests/createQuery/IsRestoringExample.svelte, packages/svelte-query/tests/createQuery/createQuery.svelte.test.ts
Example component accepts queryClient as prop (type-only import); test passes client to component during rendering.
mutationOptions
packages/svelte-query/tests/mutationOptions/BaseExample.svelte, packages/svelte-query/tests/mutationOptions/MultiExample.svelte, packages/svelte-query/tests/mutationOptions/mutationOptions.svelte.test.ts
Both example components refactored to accept queryClient prop (type-only import); test creates per-test client, clears in afterEach, and passes to all component render calls.
useIsFetching
packages/svelte-query/tests/useIsFetching/BaseExample.svelte, packages/svelte-query/tests/useIsFetching/useIsFetching.svelte.test.ts
Component accepts queryClient prop (type-only import); test instantiates per-test client and passes via props with cleanup in afterEach.
useIsMutating
packages/svelte-query/tests/useIsMutating/BaseExample.svelte, packages/svelte-query/tests/useIsMutating/useIsMutating.svelte.test.ts
Component accepts queryClient prop (type-only import); test creates per-test client and injects via props with cleanup.
useMutationState
packages/svelte-query/tests/useMutationState/BaseExample.svelte, packages/svelte-query/tests/useMutationState/SelectExample.svelte, packages/svelte-query/tests/useMutationState/useMutationState.svelte.test.ts
Both example components updated to accept queryClient prop (type-only import); test creates shared client per test lifecycle and passes to all rendered examples.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Props now dance where once they grew,
QueryClients passed on through and through!
No more constructors in the test,
Dependency injection does its best! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the main change: extracting queryClient creation from Svelte components to test files, which aligns with all file modifications shown in the summary.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The PR description provides comprehensive coverage of all changes, including extraction of queryClient creation, test file modifications, and variable renaming. All required checklist items are addressed.

✏️ 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/svelte-query-extract-queryClient-to-test-files

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

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

nx-cloud bot commented Apr 11, 2026

View your CI Pipeline Execution ↗ for commit 0c9d97f

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

☁️ Nx Cloud last updated this comment at 2026-04-11 06:08:38 UTC

@github-actions
Copy link
Copy Markdown
Contributor

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

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 0c9d97f

@github-actions
Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
react full 11.99 KB (0%)
react minimal 9.02 KB (0%)

@sukvvon sukvvon merged commit 1881109 into main Apr 11, 2026
8 checks passed
@sukvvon sukvvon deleted the test/svelte-query-extract-queryClient-to-test-files branch April 11, 2026 06:16
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