Recursively trigger OnModuleDestroy hook for testing module
I'm submitting a...
[ ] Regression
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
I would like to be able to trigger the OnModuleDestroy function for test modules created in my tests. However, this is not possible, the only method exposed is the init() function, which successfully recursively triggers the OnModuleInit function.
beforeEach(async () => {
module = await Test.createTestingModule(config).compile();
await module.init();
});
Expected behavior
There should be a module.close() function similar to the module.init() function, which then recursively triggers the OnModuleDestroy function for the module and all of its providers.
afterEach(async () => {
await module.destroy();
});
I noticed that a similar function already exists in nest-application.ts. It should work like that.
What is the motivation / use case for changing the behavior?
I use the OnModuleInit and OnModuleDestroy to configure certain modules. I would like to be able to clean up a module after testing, as currently some tests stay stuck after completion. This is because the destroy hook isn't being called.
This feature will be available once #903 is merged
5.2.0 is here!
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.