test(angular-query-experimental/injectQueries): switch to fake timers, replace 'setTimeout' with 'sleep', replace 'findByText' with 'getByText', add 'toBeInTheDocument', remove unused 'toString' method, rename '_pushResults' to '_', and add '@testing-library/jest-dom/vitest'
π― Changes
β Checklist
- [x] I have followed the steps in the Contributing guide.
- [x] I have tested this code locally with
pnpm run test:pr.
π Release Impact
- [ ] This change affects published code, and I have generated a changeset.
- [x] 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.
β οΈ No Changeset found
Latest commit: 503d87a9242d8613a65108f521a96f036c2c9424
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
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
Estimated code review effort
π― 2 (Simple) | β±οΈ ~12 minutes
- Areas requiring attention:
- Verify fake timer setup and teardown logic (
useFakeTimers/afterEachrestoration) - Confirm
sleeputility 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
- Verify fake timer setup and teardown logic (
Possibly related PRs
- TanStack/query#9569: Modifies the same
@testing-library/jest-dom/vitestimport handling, with complementary changes to test matchers. - TanStack/query#8690: Adds and fixes
injectQueriestests and behavior, directly related to the test improvements in this PR. - TanStack/query#9850: Implements similar fake timer and sleep utility changes across other test files, following the same testing pattern.
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.
View your CI Pipeline Execution β for commit 503d87a9242d8613a65108f521a96f036c2c9424
| Command | Status | Duration | Result |
|---|---|---|---|
nx affected --targets=test:sherif,test:knip,tes... |
β Succeeded | 2m 29s | View β |
nx run-many --target=build --exclude=examples/*... |
β Succeeded | 9s | View β |
βοΈ Nx Cloud last updated this comment at 2025-12-19 01:58:49 UTC
More templates
- @tanstack/query-example-angular-auto-refetching
- @tanstack/query-example-angular-basic
- @tanstack/query-example-angular-basic-persister
- @tanstack/query-example-angular-devtools-panel
- @tanstack/query-example-angular-infinite-query-with-max-pages
- @tanstack/query-example-angular-optimistic-updates
- @tanstack/query-example-angular-pagination
- @tanstack/query-example-angular-query-options-from-a-service
- @tanstack/query-example-angular-router
- @tanstack/query-example-angular-rxjs
- @tanstack/query-example-angular-simple
- @tanstack/query-example-solid-astro
- @tanstack/query-example-solid-basic
- @tanstack/query-example-solid-basic-graphql-request
- @tanstack/query-example-solid-default-query-function
- @tanstack/query-example-solid-simple
- @tanstack/query-example-solid-start-streaming
- @tanstack/query-example-react-algolia
- @tanstack/query-example-react-auto-refetching
- @tanstack/query-example-react-basic
- @tanstack/query-example-react-basic-graphql-request
- @tanstack/query-example-chat
- @tanstack/query-example-react-default-query-function
- @tanstack/query-example-react-devtools-panel
- @tanstack/query-example-eslint-legacy
- @tanstack/query-example-react-infinite-query-with-max-pages
- @tanstack/query-example-react-load-more-infinite-scroll
- @tanstack/query-example-react-nextjs
- @tanstack/query-example-react-nextjs-app-prefetching
- @tanstack/query-example-nextjs-suspense-streaming
- @tanstack/query-example-react-offline
- @tanstack/query-example-react-optimistic-updates-cache
- @tanstack/query-example-react-optimistic-updates-ui
- @tanstack/query-example-react-pagination
- @tanstack/query-example-react-playground
- @tanstack/query-example-react-prefetching
- @tanstack/query-example-react-react-native
- @tanstack/query-example-react-router
- @tanstack/query-example-react-rick-morty
- @tanstack/query-example-react-shadow-dom
- @tanstack/query-example-react-simple
- @tanstack/query-example-react-star-wars
- @tanstack/query-example-react-suspense
- @tanstack/query-example-svelte-auto-refetching
- @tanstack/query-example-svelte-basic
- @tanstack/query-example-svelte-load-more-infinite-scroll
- @tanstack/query-example-svelte-optimistic-updates
- @tanstack/query-example-svelte-playground
- @tanstack/query-example-svelte-simple
- @tanstack/query-example-svelte-ssr
- @tanstack/query-example-svelte-star-wars
- @tanstack/query-example-vue-2.6-basic
- @tanstack/query-example-vue-2.7-basic
- @tanstack/query-example-vue-basic
- @tanstack/query-example-vue-dependent-queries
- @tanstack/query-example-vue-nuxt3
- @tanstack/query-example-vue-persister
- @tanstack/query-example-vue-simple
@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: 503d87a
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 94.13%. Comparing base (f15b7fc) to head (503d87a).
Additional details and impacted files
@@ Coverage Diff @@
## main #9896 +/- ##
===========================================
+ Coverage 45.89% 94.13% +48.23%
===========================================
Files 200 21 -179
Lines 8437 426 -8011
Branches 1943 99 -1844
===========================================
- Hits 3872 401 -3471
+ Misses 4116 24 -4092
+ Partials 449 1 -448
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.