Error during cleanup of component: Display error too

See original GitHub issue

I’m submitting a … (check one with “x”)

[ ] bug report => search github for a similar issue or PR before submitting
[X] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior In TestBed.resetTestingModule() an error may occur. The error is not logged to the console, only the component that failed to be destroyed is logged.

Expected behavior The console.error at this line https://github.com/angular/angular/blob/master/packages/core/testing/src/test_bed.ts#L252 will also log the error.

What is the motivation / use case for changing the behavior? Currently I cannot investigate why I get this error, I’ve disabled all my ngOnDestroy’s but still getting this error.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:34
  • Comments:24 (2 by maintainers)

github_iconTop GitHub Comments

34reactions
croso-dfcommented, Mar 2, 2018

In my case, I was trying to unsubscribe from an undefined subscription in ngOnDestroy. Just verifying non-null subscription did the trick:

if (this.subscription) {
  this.subscription.unsubscribe();
}
22reactions
josuesblacommented, Apr 18, 2018

Solved by adding this to my unit tests:

afterEach(() => {
   component.ngOnDestroy();
});

But I’m not sure about why it solves it…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing Angular component with unsubscribe Error during ...
The "Error during component cleanup" error message happens because when ngOnDestroy() is called, this.routeSubscription is undefined.
Read more >
[Solved]-ERROR: 'Error during cleanup of component', Object ...
I am Getting this error while creating a new component in Angular 2.! Error when using AngularJS component inside Angular app: "Error: Trying...
Read more >
OnDestroy - Angular
A lifecycle hook that is called when a directive, pipe, or service is destroyed. Use for any custom cleanup that needs to occur...
Read more >
API Reference | React Hooks Testing Library
A React component to wrap the test component in when rendering. ... These could be result or an error depending on what the...
Read more >
Testing Angular Components with Stub Services and Spies in ...
you'll be greeted with an error message of StaticInjectorError: To fix this you need to import HttpClientModule in TestBed because we are using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found