Insert services that uses Angular classes as dependency in UpgradedServices
See original GitHub issueIs your feature request related to a problem? Please describe.
I’m trying to insert EmailDashboardDataService
, which uses HttpClient
as a dependency in UpgradedServices
file:
upgradedServices['EmailDashboardDataService'] =
new EmailDashboardDataService();
But it needs the HttpClient
object instance. HttpClient
uses dependencies as well and its dependencies use other dependencies and so on.
Describe the solution you’d like
Insert services that use third-party classes as dependencies in UpgradedService
using a clean way.
Describe alternatives you’ve considered
Here’s the approach I’ve found but I think it is not right. I’ve searched non-abstract classes that implement the dependency of the previous dependency. For example, HttpXhrBackend
implements HttpHandler
, an abstract class. HttpBackend
uses HttpHandler
type as a dependency.
upgradedServices['EmailDashboardDataService'] =
new EmailDashboardDataService(
new HttpClient(new HttpXhrBackend(new ɵangular_packages_common_http_http_d())));
How can we find a better solution for this service and future ones?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
Hey @marianazangrossi,
I did tried the approach that you mentioned, though I used BrowserXrf rather than some angular_packages as you used.
The problem with this approach is the frontend tests still fail and definitely if we are adding any service in upgradedService we are doing it for frontend tests. So, I’ll explain you whole case in detail.
Let me give you an example. I was migrating the service
question-backend-api.service.ts
. Now, this service usesHttpClient
. Thequestions-list.service
uses QuestionBackendApiService. Look at thequestions-list.service.spec.ts
and particularly the following part:qls.getQuestionSummariesAsync()
this function uses QuestionBackendApiService to create the request. The request is created viaHttpClient
now since QuestionBackendApiService is migrated to Angular. Hence, there is no request to flush or test via$httpBackend
and that gives a errorError: No request to flush!
. The request created byHttpClient
is tested or flushed viaHttpClientTestingModule
and not by$httpBackend
(which is used when service handles request via$http
). I need to modify such tests where ever they fail.This is one solution that we have and yes we can go ahead with this because at last we are modifying all tests right so it’s not waste of effort to do it right now.
There is one other thing: createAngularJSTestingModule. I tried using this as well but I failed.
I think I explained you, please let me know if you any questions.
Now, question for you – Why do you want this service in UpgradedServices since I checked this service is not being used in any other service?
This is not required anymore since the angular injector error is solved.