Skip to content

test(angular-query-experimental/injectIsFetching): switch main test to '@Component' + 'render' pattern#10556

Merged
sukvvon merged 1 commit intomainfrom
test/angular-query-inject-is-fetching-render-pattern
Apr 22, 2026
Merged

test(angular-query-experimental/injectIsFetching): switch main test to '@Component' + 'render' pattern#10556
sukvvon merged 1 commit intomainfrom
test/angular-query-inject-is-fetching-render-pattern

Conversation

@sukvvon
Copy link
Copy Markdown
Collaborator

@sukvvon sukvvon commented Apr 22, 2026

🎯 Changes

Rewrites the main test in inject-is-fetching.test.ts to use a @Component + @testing-library/angular's render instead of calling TestBed.runInInjectionContext and asserting on the signal value directly. The assertion now checks the rendered DOM text, which mirrors how a user actually observes injectIsFetching in an Angular component.

Before

it('should return the number of fetching queries', async () => {
  const key = queryKey()
  const isFetching = TestBed.runInInjectionContext(() => {
    injectQuery(() => ({
      queryKey: key,
      queryFn: () => sleep(100).then(() => 'Some data'),
    }))
    return injectIsFetching()
  })

  expect(isFetching()).toStrictEqual(0)
  await vi.advanceTimersByTimeAsync(1)
  expect(isFetching()).toStrictEqual(1)
  await vi.advanceTimersByTimeAsync(100)
  expect(isFetching()).toStrictEqual(0)
})

After

it('should return the number of fetching queries', async () => {
  const key = queryKey()

  @Component({
    template: `<div>fetching: {{ isFetching() }}</div>`,
  })
  class Page {
    readonly query = injectQuery(() => ({
      queryKey: key,
      queryFn: () => sleep(100).then(() => 'Some data'),
    }))
    readonly isFetching = injectIsFetching()
  }

  const rendered = await render(Page)

  expect(rendered.getByText('fetching: 0')).toBeInTheDocument()

  await vi.advanceTimersByTimeAsync(0)
  rendered.fixture.detectChanges()
  expect(rendered.getByText('fetching: 1')).toBeInTheDocument()

  await vi.advanceTimersByTimeAsync(101)
  rendered.fixture.detectChanges()
  expect(rendered.getByText('fetching: 0')).toBeInTheDocument()
})

Why

  • Matches the component-based usage shown in the official Angular guide (`docs/framework/angular/guides/background-fetching-indicators.md`) and across `examples/angular/*`.
  • `readonly` fields on the test component follow the convention used in our Angular examples (`readonly query = injectQuery(...)`, `readonly isFetching = injectIsFetching()`).
  • The `injection context` describe block (NG0203 throw / passing an injector) is kept as-is — those checks don't need a rendered component.

Verification

  • `@tanstack/angular-query-experimental` — 209 tests passed, 0 type errors

✅ 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).

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 22, 2026

📝 Walkthrough

Walkthrough

Refactored a test to validate injectIsFetching() via a rendered Angular component and DOM assertions using @testing-library/angular's render(), replacing direct invocation inside TestBed.runInInjectionContext() and per-step callable checks with template text checks and fixture.detectChanges() after advancing fake timers.

Changes

Cohort / File(s) Summary
Test Refactor
packages/angular-query-experimental/src/__tests__/inject-is-fetching.test.ts
Replaced direct TestBed.runInInjectionContext() invocation with a component (Page) that uses injectQuery(...) and exposes isFetching = injectIsFetching(). Switched assertions from calling isFetching() at timer steps to checking DOM text (fetching: 0/1). Added fixture.detectChanges() after advancing fake timers to refresh template output.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I hopped into tests with a curious grin,
Swapped bare calls for a component within,
Timers tick-tock, the DOM shows the tale,
detectChanges breathes life, assertions prevail. 🎩

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: refactoring a test to use an Angular @Component with the render pattern instead of TestBed.runInInjectionContext.
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.
Description check ✅ Passed The PR description is comprehensive and includes all required sections from the template with completed checklists and clear context.

✏️ 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/angular-query-inject-is-fetching-render-pattern

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

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 22, 2026

View your CI Pipeline Execution ↗ for commit 05228ca

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

☁️ Nx Cloud last updated this comment at 2026-04-22 05:41:52 UTC

@github-actions
Copy link
Copy Markdown
Contributor

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

More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: 05228ca

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 22, 2026

size-limit report 📦

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

@sukvvon sukvvon force-pushed the test/angular-query-inject-is-fetching-render-pattern branch from 9f20f1d to 05228ca Compare April 22, 2026 05:38
@sukvvon sukvvon self-assigned this Apr 22, 2026
@sukvvon sukvvon merged commit f01b7ce into main Apr 22, 2026
8 checks passed
@sukvvon sukvvon deleted the test/angular-query-inject-is-fetching-render-pattern branch April 22, 2026 05:44
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