mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-09-02 13:52:46 +02:00
docs(angular): update services with dependencies content (#6915)
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user