Open arunselvakumar opened 5 years ago
TestBed.get(ToDoService) -> Get the instance, only if the provider is registered in the application level. ie., at the module level.
To get the providers, which are registered in the component level - We need to use the following code.
fixture.debugElement.injector.get(ToDoService);
.and.returnValue(Observable.from([[1,2,3]]));
fixture.detectChanges() => Calls ngOnInit, so the dependency should be injected before that.
Providers provided in the module level are singleton Providers provided in the component level are created for every instances of the component.