how to test all my Service are injected into component
class TestComponent {
constructor(testService: TestService) {}
}
in case if anybody remove the service from component constructor my test case should fail.
how to test all my Service are injected into component
class TestComponent {
constructor(testService: TestService) {}
}
in case if anybody remove the service from component constructor my test case should fail.
We can make TestBed as a dummy Angular Module and we can configure it like one including with a set of providers,
TestBed.configureTestingModule({
providers: [TestService]
});
Then resolve a token into a dependency using it’s internal injector and TestBed,
testBedService = TestBed.get(TestService);
Then your test case be like,
it('Service injected via inject(...) and TestBed.get(...) should be the same instance',
inject([TestService], (injectService: TestService) => {
expect(injectService).toBe(testBedService);
})
);
Refer https://codecraft.tv/courses/angular/unit-testing/dependency-injection/