Skip to content

Conversation

@sukvvon
Copy link
Contributor

@sukvvon sukvvon commented Nov 23, 2025

🎯 Changes

βœ… 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
    • Enhanced test infrastructure with fake timer support for timing-dependent test scenarios.
    • Improved test setup with better provider configuration for query testing.
    • Added refined test utilities and assertion mechanisms for DOM validation after asynchronous operations.
    • Upgraded test environment matchers for more comprehensive testing capabilities.

✏️ Tip: You can customize this high-level summary in your review settings.

…, replace 'setTimeout' with 'sleep', replace 'findByText' with 'getByText', add 'toBeInTheDocument', remove unused 'toString' method, rename '_pushResults' to '_', and add '@testing-library/jest-dom/vitest'
@changeset-bot
Copy link

changeset-bot bot commented Nov 23, 2025

⚠️ No Changeset found

Latest commit: 32a3378

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 23, 2025

Walkthrough

This PR enhances test infrastructure for Angular Query Experimental by adding fake timer support to the inject-queries test, introducing a sleep utility for cleaner async handling, and adding Jest DOM matchers to the global test setup for improved assertions.

Changes

Cohort / File(s) Summary
Test fixture enhancements
packages/angular-query-experimental/src/__tests__/inject-queries.test.ts
Implements fake timer testing with useFakeTimers, replaces manual Promise delays with sleep utility, adds advanceTimersByTimeAsync(101) for timer control, extends test setup with zoneless change detection and TanStackQuery provider, refactors result-tracking mechanism, and adds DOM assertions after timer advancement.
Test environment setup
packages/angular-query-experimental/test-setup.ts
Adds @testing-library/jest-dom/vitest import to extend Jest DOM matchers globally in the test environment.

Sequence Diagram

sequenceDiagram
    participant Test as Test Case
    participant Timer as Fake Timers
    participant Component as Angular Component
    participant DOM as DOM
    
    Test->>Timer: useFakeTimers()
    Test->>Component: render with providers
    Test->>Component: trigger async query
    Note over Component: Query in progress
    Test->>Timer: advanceTimersByTimeAsync(101)
    Timer->>Component: timer advances
    Test->>Component: detectChanges()
    Component->>DOM: update rendered content
    Test->>DOM: assert text content
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Areas requiring attention:
    • Verify fake timer setup and teardown logic (useFakeTimers/afterEach restoration)
    • Confirm sleep utility integration and async chaining correctness
    • Validate that advanceTimersByTimeAsync(101) correctly simulates the intended delay behavior
    • Review the test refactoring of result-tracking mechanism to ensure no loss of coverage

Possibly related PRs

Suggested reviewers

  • arnoud-dv
  • manudeli

Poem

🐰 Timers tick in jest's domain,
Sleep replaces Promise's chain,
Fake time flows at our command,
DOM assertions firmly stand,
Tests grow stronger, bugs take flight! ✨

Pre-merge checks and finishing touches

βœ… Passed checks (3 passed)
Check name Status Explanation
Title check βœ… Passed The title directly and comprehensively summarizes all the key changes made in the PR, including switching to fake timers, replacing setTimeout with sleep, replacing findByText with getByText, adding toBeInTheDocument, removing toString, renaming _pushResults to _, and adding the jest-dom/vitest import.
Description check βœ… Passed The PR description follows the provided template with all required sections completed: Changes section present (though brief), checklist items properly marked, and Release Impact correctly indicating dev-only changes with no changeset needed.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • πŸ“ Generate docstrings
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@nx-cloud
Copy link

nx-cloud bot commented Nov 23, 2025

View your CI Pipeline Execution β†— for commit 32a3378

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... βœ… Succeeded 2m 41s View β†—
nx run-many --target=build --exclude=examples/*... βœ… Succeeded 8s View β†—

☁️ Nx Cloud last updated this comment at 2025-11-23 14:03:13 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 23, 2025

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 32a3378

@codecov
Copy link

codecov bot commented Nov 23, 2025

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 94.13%. Comparing base (ae47807) to head (32a3378).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #9896       +/-   ##
===========================================
+ Coverage   45.70%   94.13%   +48.42%     
===========================================
  Files         200       21      -179     
  Lines        8437      426     -8011     
  Branches     1936       99     -1837     
===========================================
- Hits         3856      401     -3455     
+ Misses       4133       24     -4109     
+ Partials      448        1      -447     
Components Coverage Ξ”
@tanstack/angular-query-experimental 93.85% <ΓΈ> (ΓΈ)
@tanstack/eslint-plugin-query βˆ… <ΓΈ> (βˆ…)
@tanstack/query-async-storage-persister βˆ… <ΓΈ> (βˆ…)
@tanstack/query-broadcast-client-experimental βˆ… <ΓΈ> (βˆ…)
@tanstack/query-codemods βˆ… <ΓΈ> (βˆ…)
@tanstack/query-core βˆ… <ΓΈ> (βˆ…)
@tanstack/query-devtools βˆ… <ΓΈ> (βˆ…)
@tanstack/query-persist-client-core βˆ… <ΓΈ> (βˆ…)
@tanstack/query-sync-storage-persister βˆ… <ΓΈ> (βˆ…)
@tanstack/query-test-utils βˆ… <ΓΈ> (βˆ…)
@tanstack/react-query βˆ… <ΓΈ> (βˆ…)
@tanstack/react-query-devtools βˆ… <ΓΈ> (βˆ…)
@tanstack/react-query-next-experimental βˆ… <ΓΈ> (βˆ…)
@tanstack/react-query-persist-client βˆ… <ΓΈ> (βˆ…)
@tanstack/solid-query βˆ… <ΓΈ> (βˆ…)
@tanstack/solid-query-devtools βˆ… <ΓΈ> (βˆ…)
@tanstack/solid-query-persist-client βˆ… <ΓΈ> (βˆ…)
@tanstack/svelte-query βˆ… <ΓΈ> (βˆ…)
@tanstack/svelte-query-devtools βˆ… <ΓΈ> (βˆ…)
@tanstack/svelte-query-persist-client βˆ… <ΓΈ> (βˆ…)
@tanstack/vue-query βˆ… <ΓΈ> (βˆ…)
@tanstack/vue-query-devtools βˆ… <ΓΈ> (βˆ…)
πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • πŸ“¦ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sukvvon sukvvon marked this pull request as ready for review November 23, 2025 14:04
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/angular-query-experimental/src/__tests__/inject-queries.test.ts (1)

66-71: Consider whether TestBed providers duplication is necessary.

The providers are configured in both TestBed.configureTestingModule (lines 19-21) and in the render call here. Since @testing-library/angular creates its own TestBed module, the explicit providers in render may be sufficient for test isolation. However, if other tests in this suite rely on the global TestBed configuration, the current approach is fine.

πŸ“œ Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between c9bc600 and 32a3378.

πŸ“’ Files selected for processing (2)
  • packages/angular-query-experimental/src/__tests__/inject-queries.test.ts (3 hunks)
  • packages/angular-query-experimental/test-setup.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
πŸ““ Common learnings
Learnt from: sukvvon
Repo: TanStack/query PR: 9892
File: packages/solid-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx:331-335
Timestamp: 2025-11-22T09:06:05.219Z
Learning: In TanStack/query test files, when a queryFn contains side effects (e.g., setting flags for test verification), prefer async/await syntax for clarity; when there are no side effects, prefer the .then() pattern for conciseness.
πŸ“š Learning: 2025-08-19T03:18:18.303Z
Learnt from: oscartbeaumont
Repo: TanStack/query PR: 9564
File: packages/solid-query-devtools/src/production.tsx:2-3
Timestamp: 2025-08-19T03:18:18.303Z
Learning: In the solid-query-devtools package, the codebase uses a pattern of type-only default imports combined with typeof for component type annotations (e.g., `import type SolidQueryDevtoolsComp from './devtools'` followed by `typeof SolidQueryDevtoolsComp`). This pattern is consistently used across index.tsx and production.tsx files, and the maintainers prefer consistency over changing this approach.

Applied to files:

  • packages/angular-query-experimental/test-setup.ts
πŸ“š Learning: 2025-09-21T00:31:02.518Z
Learnt from: arnoud-dv
Repo: TanStack/query PR: 9669
File: docs/framework/angular/guides/testing.md:49-56
Timestamp: 2025-09-21T00:31:02.518Z
Learning: TestBed.tick() is a valid API introduced in Angular 20 for triggering effects in unit tests, similar to ApplicationRef.tick() but for testing contexts.

Applied to files:

  • packages/angular-query-experimental/test-setup.ts
  • packages/angular-query-experimental/src/__tests__/inject-queries.test.ts
πŸ“š Learning: 2025-11-22T09:06:05.219Z
Learnt from: sukvvon
Repo: TanStack/query PR: 9892
File: packages/solid-query-persist-client/src/__tests__/PersistQueryClientProvider.test.tsx:331-335
Timestamp: 2025-11-22T09:06:05.219Z
Learning: In TanStack/query test files, when a queryFn contains side effects (e.g., setting flags for test verification), prefer async/await syntax for clarity; when there are no side effects, prefer the .then() pattern for conciseness.

Applied to files:

  • packages/angular-query-experimental/src/__tests__/inject-queries.test.ts
πŸ”‡ Additional comments (6)
packages/angular-query-experimental/test-setup.ts (1)

1-1: LGTM!

The jest-dom import correctly extends Vitest with DOM matchers like toBeInTheDocument() used in the test file.

packages/angular-query-experimental/src/__tests__/inject-queries.test.ts (5)

1-1: LGTM!

The import additions correctly support the fake timer migration: vi and afterEach for timer setup/teardown, and sleep for cleaner async handling.

Also applies to: 8-9


16-16: LGTM!

The fake timer setup follows the standard Vitest pattern with proper cleanup in afterEach to prevent timer leaks between tests.

Also applies to: 26-28


60-63: LGTM!

The naming change from _pushResults to _ follows the convention for internal/private properties and maintains the same functionality.


73-76: LGTM!

The timer advancement and assertion logic is correct:

  • advanceTimersByTimeAsync(101) covers both delays (10ms and 100ms)
  • detectChanges() updates the DOM after timer advancement
  • Using getByText (synchronous) is appropriate after manual timer advancement
  • The toBeInTheDocument() matcher is available via the jest-dom setup

51-51: No issues found.

The sleep utility from @tanstack/query-test-utils uses setTimeout internally, which is fully compatible with Vitest's vi.useFakeTimers(). The test file properly enables fake timers at line 16, so the sleep delays will be controlled by the test framework. The .then() pattern used at lines 51 and 55 is appropriate since the queryFn has no side effects, consistent with established patterns in the codebase.

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