Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save azanebrain/76e7ca8b3c7b493483198c510bb9c80a to your computer and use it in GitHub Desktop.
Save azanebrain/76e7ca8b3c7b493483198c510bb9c80a to your computer and use it in GitHub Desktop.
Overriding a non-singleton service in an Angular component test ~ http://azanebrain.github.io/news/angular-snafoo-testing-component-with-overriden-providers
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [MyComponentModule],
providers: [
{ provide: SomeSingletonService, useValue: new SomeSingletonServiceMock() }
]
})
.overrideComponent(MyCompComponent, {
set: {
providers: [
{ provide: NonSingletonService, useClass: NonSingletonServiceMock }
]
}
})
.compileComponents()
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment