Skip to content

Commit aa63c96

Browse files
committed
docs: see preview env
1 parent 4b35e75 commit aa63c96

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

content/recipes/automock.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ test development by automatically mocking class external dependencies.
77
#### Introduction
88

99
The dependency injection container is an essential component of the Nest module system.
10-
This container is utilized both during the testing phase and the application runtime.
11-
10+
This container is utilized both during the testing phase and the application runtime. \
1211
Unit tests vary from other types of tests, such as integration tests, in that they must
1312
fully override providers/services within the DI container. External dependencies (providers)
1413
of the so-called "unit" should be totally isolated. That is, all dependencies within
15-
the DI container should be replaced by mock objects.
16-
14+
the DI container should be replaced by mock objects. \
1715
As a result, loading the modules and replacing the providers inside them is a process that
1816
loops back on itself. Automock tackles this issue by automatically mocking all the
1917
external dependencies/providers, resulting in total isolation of the unit/class
@@ -31,9 +29,7 @@ Automock does not require any additional setup.
3129
Sinon will shortly be released.
3230

3331
#### Example
34-
3532
Consider the following cats service, which takes three constructor parameters:
36-
3733
```ts
3834
@@filename(cats.service)
3935
import { Injectable } from '@nestjs/core';
@@ -96,7 +92,6 @@ describe('Cats Service Unit Spec', () => {
9692
> info **info** The jest.Mocked<Source> utility type returns the Source type
9793
> wrapped with type definitions of Jest mock function. ([reference](https://jestjs.io/docs/mock-function-api/#jestmockedsource))
9894
99-
\
10095
#### About `unit` and `unitRef`
10196
Let's examine the following code:
10297

@@ -106,14 +101,12 @@ const { unit, unitRef } = Spec.create(CatsService).compile();
106101

107102
Calling `.compile()` returns an object with two properties, `unit`, and `unitRef`.
108103

109-
`unitRef` is a small container which holds the class external dependencies (that
104+
**`unitRef`** is a small container which holds the class external dependencies (that
110105
has been replaced with mocks).
111106
It has one method, `get()`, which returns the mocked dependency, thus,
112107
it enables all the stubbing options from Jest.
113108

114-
> info **info** unitRef.get() takes a string (token) or a class (dependency)
115-
116-
`unit` is the actual unit under test, it's an instance of the tested class.
109+
**`unit`** is the actual unit under test, it's an instance of the tested class.
117110

118111
#### Handling Different Scenarios
119112
Nest offers different ways to retrieve dependencies from the DI container:

0 commit comments

Comments
 (0)