Skip to content

feat: add componentProviders for component-level dependency injection#16

Merged
shairez merged 3 commits into
mainfrom
pr-comp-providers
Jan 13, 2026
Merged

feat: add componentProviders for component-level dependency injection#16
shairez merged 3 commits into
mainfrom
pr-comp-providers

Conversation

@shairez
Copy link
Copy Markdown
Contributor

@shairez shairez commented Jan 11, 2026

Adds support for component-level dependency injection providers through the new componentProviders option in the render() function.

Implementation

  • Added componentProviders option to RenderConfig interface
  • Uses TestBed.overrideComponent() to inject providers at component level

Usage

@Component({
  template: '<h1>{{ title }}</h1>',
  providers: [GreetingService],
})
export class HelloWorldComponent {
  title = 'Hello World';
}

test('renders component with service provider', async () => {
  const { component } = await render(HelloWorldComponent, {
    componentProviders: [
      { provide: GreetingService, useClass: FakeGreetingService },
    ],
  });
});

This enables testing Angular components when you need to also override providers defined on their component decorator.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jan 11, 2026

Open in StackBlitz

npm i https://pkg.pr.new/vitest-community/vitest-browser-angular@16

commit: fe94a98

@shairez shairez changed the title docs: add component providers documentation feat: add componentProviders for component-level dependency injection Jan 11, 2026
@shairez shairez requested a review from yjaaidi January 11, 2026 23:28
Copy link
Copy Markdown
Contributor

@yjaaidi yjaaidi left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

Comment thread README.md Outdated
Co-authored-by: Younes Jaaidi <yjaaidi@gmail.com>
@shairez shairez merged commit 7c7c62d into main Jan 13, 2026
3 checks passed
@github-actions github-actions Bot mentioned this pull request Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants