Last active
January 25, 2018 19:41
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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