docs(angular): update services with dependencies content (#6915)

pull/6930/head
J. Degand 3 months ago committed by GitHub
parent 3acc0d6a5f
commit 512de27478
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      src/data/roadmaps/angular/content/services-with-dependencies@TGRZBizDy83JKg_MhnRdX.md

@ -1,9 +1,11 @@
# Testing services
# Testing services with dependencies
In an Angular application, Services are responsible for fetching, storing and processing data. Services are singletons, meaning there is only one instance of a Service during runtime. They are fit for central data storage, HTTP and WebSocket communication as well as data validation.
When you add a dependency to your service, you must also include it in your tests. For isolated tests, pass an instance of the injectable dependency class into the service’s constructor. Using the `inject` function can add complexity. Injecting the real service is often impractical because dependent services can be difficult to create and control. Instead, mock the dependency, use a dummy value, or create a spy on the relevant service method. By using the TestBed testing utility, you can let Angular’s dependency injection handle service creation and manage constructor argument order.
Visit the following resources to learn more:
- [@official@Angular Website](https://angular.dev/guide/testing/services)
- [@article@Testing-Angular.com](https://testing-angular.com/testing-services/)
- [@feed@Explore top posts about Testing](https://app.daily.dev/tags/testing?ref=roadmapsh)
- [@video@Testing the Service which has another service injected through Dependency Injection](https://www.youtube.com/watch?v=ACb8wqwgOV4)
- [@video@Testing Services which has HttpClient as dependency by using Jasmine Spy](https://www.youtube.com/watch?v=15othucRXcI)
- [@video@Angular Unit Tests with the inject() function](https://www.youtube.com/watch?v=Tvsa4OMUGXs)

Loading…
Cancel
Save