Skip to content

Commit

Permalink
Merge pull request #2259 from micalevisk/patch-1
Browse files Browse the repository at this point in the history
docs(fundamentals): clarify the source of `ModuleMocker` class
  • Loading branch information
kamilmysliwiec committed Mar 29, 2022
2 parents 2956409 + c5e2305 commit 9462d8a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions content/fundamentals/unit-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ Instead of using the production version of any provider, you can override it wit
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()`.

```typescript
// ...
import { ModuleMocker } from 'jest-mock';

const moduleMocker = new ModuleMocker(global);

describe('CatsController', () => {
Expand Down

0 comments on commit 9462d8a

Please sign in to comment.