@@ -51,7 +51,7 @@ export class CatsService {
51
51
}
52
52
```
53
53
54
- The service contains one public methods , ` getAllCats ` , which is the method
54
+ The service contains one public method , ` getAllCats ` , which is the method
55
55
we use an example for the following unit test:
56
56
57
57
``` ts
@@ -96,23 +96,27 @@ describe('Cats Service Unit Spec', () => {
96
96
Let's examine the following code:
97
97
98
98
``` typescript
99
- const { unit, unitRef } = Spec .create (CatsService ).compile ();
99
+ const { unit, unitRef } = TestBed .create (CatsService ).compile ();
100
100
```
101
101
102
102
Calling ` .compile() ` returns an object with two properties, ` unit ` , and ` unitRef ` .
103
103
104
- ** ` unitRef ` ** is a small container which holds the class external dependencies (that
105
- has been replaced with mocks).
106
- It has one method, ` get() ` , which returns the mocked dependency, thus,
107
- it enables all the stubbing options from Jest.
104
+ ** ` unit ` ** is the "unit" (service/provider) under test, it is an actual instance of
105
+ class being tested (also known as "unit under test").
108
106
109
- ** ` unit ` ** is the actual unit under test, it's an instance of the tested class.
107
+ To store the mocked dependencies of the tested class, the "unit reference" (` unitRef ` )
108
+ serves as a small container. The container's ` .get() ` method returns the mocked
109
+ dependency with all of its methods automatically stubbed (using ` jest.fn() ` ).
110
110
111
- #### Handling Different Scenarios
112
- Nest offers different ways to retrieve dependencies from the DI container:
113
- Actual class, injection tokens, and forwardRef functions. They all can be
114
- replaced with mocks using different techniques, in the next sections you
115
- can understand how to deal with each scenario
111
+ The ` .get() ` method can accept either a ` string ` or an actual class (` Type ` ) as its argument.
112
+ This essentially depends on how the class dependency is being injected.
113
+ Some specific usage scenarios, including when a ` string ` and when a ` Type ` are acceptable,
114
+ are provided below.
115
+
116
+ #### Handling Different Injections Types
117
+ Providers are one of the most important ideas in Nest. A lot of the basic Nest classes,
118
+ such as services, repositories, factories, helpers, and so on, can be treated of as providers.
119
+ The main idea behind a provider is that it can be injected as a dependency.
116
120
117
121
##### Working with Interfaces
118
122
Consider the following ` CatsService ` which takes one param which is an instance
0 commit comments