Skip to content

Commit 8f1b656

Browse files
Merge pull request #2484 from micalevisk/patch-4
docs(fundamentals): add mention on limitation of auto mocking & overrideProvider
2 parents beb883b + 1ccdf76 commit 8f1b656

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

content/fundamentals/unit-testing.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,11 @@ describe('CatsController', () => {
195195
});
196196
```
197197

198+
You can also retrieve these mocks out of the testing container as you normally would custom providers, `moduleRef.get(CatsService)`.
199+
198200
> info **Hint** A general mock factory, like `createMock` from [`@golevelup/ts-jest`](https://github.com/golevelup/nestjs/tree/master/packages/testing) can also be passed directly.
199201
200-
You can also retrieve these mocks out of the testing container as you normally would custom providers, `moduleRef.get(CatsService)`.
202+
> info **Hint** `REQUEST` and `INQUIRER` providers cannot be auto-mocked because they're already pre-defined in the context. However, they can be _overwritten_ using the custom provider syntax or by utilizing the `.overrideProvider` method.
201203
202204
#### End-to-end testing
203205

@@ -324,6 +326,8 @@ Each of the override methods returns an object with 3 different methods that mir
324326
Each of the override method types, in turn, returns the `TestingModule` instance, and can thus be chained with other methods in the [fluent style](https://en.wikipedia.org/wiki/Fluent_interface). You should use `compile()` at the end of such a chain to cause Nest to instantiate and initialize the module.
325327
326328
Also, sometimes you may want to provide a custom logger e.g. when the tests are run (for example, on a CI server). Use the `setLogger()` method and pass an object that fulfills the `LoggerService` interface to instruct the `TestModuleBuilder` how to log during tests (by default, only "error" logs will be logged to the console).
329+
330+
> warning **Warning** The `@nestjs/core` package exposes unique provider tokens with the `APP_` prefix to help on define global enhancers. Those tokens cannot be overriden since they can represent multiple providers. Thus you can't use `.overrideProvider(APP_GUARD)` (and so on). If you want to override some global enhancer, follow [this workaround](https://github.com/nestjs/nest/issues/4053#issuecomment-585612462).
327331
328332
The compiled module has several useful methods, as described in the following table:
329333

0 commit comments

Comments
 (0)