nest: TestingModuleBuilder is missing overrideModule

Feature Request

Is your feature request related to a problem? Please describe.

I want to use mock modules to override functionalities of the module instead of overriding internals of the module again and again.

Describe the solution you’d like

A overrideModule method similar to overrideProvider would solve the issue, example:

Test.createTestingModule({
  ...
})
  .overrideModule(LoggerModule)
  .useClass(LoggerTestingModule)
  .compile();

What is the motivation / use case for changing the behavior?

For the cases of e2e / integration testing in a project with many encapsulated libraries / modules it would be very helpful to be able to override entire modules instead of overriding internals of the modules every time the module is part of a testing module.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 31
  • Comments: 16 (4 by maintainers)

Most upvoted comments

Do we have any updates on the PR? https://github.com/nestjs/nest/pull/8777

I could really use this feature! 😃

I will build a solution if i can find some time

As far as I can tell this has been added to nestjs 10 ?!

Yet the injected “CACHE_MANAGER” does not use the settings from the overwritten module:

I had a similar issue with a DynamicModule. I got a suggestion on how to tackle it in https://github.com/nestjs/nest/issues/11967. It might help with your use-case.

Hi everyone, good evening. I took some time last week to add this functionality on testing-module.builder.ts API.

Maintainers(cc: @kamilmysliwiec) when you have time please, take a look at this PR.

See withModule method in TestModuleBuilder from @jbiskur/nestjs-test-utilities