Skip to content
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

Recursively trigger OnModuleDestroy hook for testing module #899

Closed
moesjarraf opened this issue Jul 24, 2018 · 3 comments
Closed

Recursively trigger OnModuleDestroy hook for testing module #899

moesjarraf opened this issue Jul 24, 2018 · 3 comments

Comments

@moesjarraf
Copy link

moesjarraf commented Jul 24, 2018

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.

@kamilmysliwiec
Copy link
Member

This feature will be available once #903 is merged

@kamilmysliwiec
Copy link
Member

5.2.0 is here!

@lock
Copy link

lock bot commented Sep 24, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants