-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TestingModuleBuilder is missing overrideModule #4905
Comments
Sounds interesting! Would you like to try to create a PR for this issue? |
I'm testing in a hyper-microservice environment and I could really use this feature. I was on the cusp of giving up on nestjs e2e testing entirely and just do unit and integration tests (e.g. Postman) because I was loosing too much time on figuring out why certain mocks work and others don't. @oschlegel let me know how I can help. |
I will build a solution if i can find some time |
This is exactly what I need. I'm working in a application that has one module whose uses several services from another modules and override all internals imports modules is very painful |
Any news on this one? Would be really helpful! Can anyone give an estimate? |
@NilsLeger feel free to contribute to this issue, PRs are more than welcome! |
See |
Hi everyone, good evening. I took some time last week to add this functionality on Maintainers(cc: @kamilmysliwiec) when you have time please, take a look at this PR. |
Thanks @leonardovillela! Let's track this here #8777 |
Do we have any updates on the PR? #8777 I could really use this feature! :) |
I concur. Would be very useful. |
+1 |
1 similar comment
+1 |
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:
class MockCacheModule extends CacheModule {
static override register<StoreConfig extends Record<any, any> = Record<string, any>>(
options?: CacheModuleOptions<StoreConfig>,
): DynamicModule {
return CacheModule.register({ ...options, ttl: 100 });
}
}
const module = await Test.createTestingModule({
imports: [DatabaseModule],
})
.overrideProvider(ProjectConfigService)
.useClass(ProjectConfigTestService)
.overrideModule(CacheModule)
.useModule(MockCacheModule)
.compile(); |
I had a similar issue with a |
@fmrsabino thank you, now that I think about it, this makes perfect sense. Exporting the module config which uses the dynamic cache module and then overwriting that module instance worked as expected. // [...]
const module = await Test.createTestingModule({
imports: [DatabaseModule],
})
.overrideModule(dynamicDatabaseCacheModule)
.useModule(
CacheModule.register({
ttl: 100,
}),
)
.compile();
// [...] |
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 tooverrideProvider
would solve the issue, example: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.
The text was updated successfully, but these errors were encountered: