Skip to content

Commit 3cb94e8

Browse files
committed
docs: remove invalid service dependency guide section
The current section `Services with dependencies` within the testing services guide is non-functional and has been removed. The example service is using `inject` but the test code is using constructor-based injection. The further sections discuss the use of TestBed to adjust providers which better handles these cases.
1 parent 0efb3f6 commit 3cb94e8

File tree

1 file changed

+0
-28
lines changed

1 file changed

+0
-28
lines changed

adev/src/content/guide/testing/services.md

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,6 @@ Here are some synchronous and asynchronous unit tests of the `ValueService` writ
77

88
<docs-code header="app/demo/demo.spec.ts" path="adev/src/content/examples/testing/src/app/demo/demo.spec.ts" visibleRegion="ValueService"/>
99

10-
## Services with dependencies
11-
12-
Services often depend on other services that Angular injects into the constructor.
13-
In many cases, you can create and _inject_ these dependencies by hand while calling the service's constructor.
14-
15-
The `MasterService` is a simple example:
16-
17-
<docs-code header="app/demo/demo.ts" path="adev/src/content/examples/testing/src/app/demo/demo.ts" visibleRegion="MasterService"/>
18-
19-
`MasterService` delegates its only method, `getValue`, to the injected `ValueService`.
20-
21-
Here are several ways to test it.
22-
23-
<docs-code header="app/demo/demo.spec.ts" path="adev/src/content/examples/testing/src/app/demo/demo.spec.ts" visibleRegion="MasterService"/>
24-
25-
The first test creates a `ValueService` with `new` and passes it to the `MasterService` constructor.
26-
27-
However, injecting the real service rarely works well as most dependent services are difficult to create and control.
28-
29-
Instead, mock the dependency, use a dummy value, or create a [spy](https://jasmine.github.io/tutorials/your_first_suite#section-Spies) on the pertinent service method.
30-
31-
HELPFUL: Prefer spies as they are usually the best way to mock services.
32-
33-
These standard testing techniques are great for unit testing services in isolation.
34-
35-
However, you almost always inject services into application classes using Angular dependency injection and you should have tests that reflect that usage pattern.
36-
Angular testing utilities make it straightforward to investigate how injected services behave.
37-
3810
## Testing services with the `TestBed`
3911

4012
Your application relies on Angular [dependency injection (DI)](guide/di) to create services.

0 commit comments

Comments
 (0)