Skip to content

Commit 9462d8a

Browse files
Merge pull request #2259 from micalevisk/patch-1
docs(fundamentals): clarify the source of `ModuleMocker` class
2 parents 2956409 + c5e2305 commit 9462d8a

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

content/fundamentals/unit-testing.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ Instead of using the production version of any provider, you can override it wit
165165
Nest also allows you to define a mock factory to apply to all of your missing dependencies. This is useful for cases where you have a large number of dependencies in a class and mocking all of them will take a long time and a lot of setup. To make use of this feature, the `createTestingModule()` will need to be chained up with the `useMocker()` method, passing a factory for your dependency mocks. This factory can take in an optional token, which is an instance token, any token which is valid for a Nest provider, and returns a mock implementation. The below is an example of creating a generic mocker using [`jest-mock`](https://www.npmjs.com/package/jest-mock) and a specific mock for `CatsService` using `jest.fn()`.
166166

167167
```typescript
168+
// ...
169+
import { ModuleMocker } from 'jest-mock';
170+
168171
const moduleMocker = new ModuleMocker(global);
169172

170173
describe('CatsController', () => {

0 commit comments

Comments
 (0)