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

AccordionTab throwing ViewDestroyedError during unit testing #8044

Closed
brian428 opened this issue Aug 9, 2019 · 7 comments · Fixed by #8127
Closed

AccordionTab throwing ViewDestroyedError during unit testing #8044

brian428 opened this issue Aug 9, 2019 · 7 comments · Fixed by #8127
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@brian428
Copy link
Contributor

brian428 commented Aug 9, 2019

I'm submitting a ... (check one with "x")

[X] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Plunkr Case (Bug Reports)
Unfortunately, I'm not sure how to create a demo of the problem because the problem only manifests during unit testing. However, the source of the problem is very straightforward:

  1. If a spec completes (e.g. calls done()) before the Accordion finishes animating, a ViewDestroyedError: Attempt to use a destroyed view: detectChanges is thrown.
  2. When the animation finishes, it triggers onToggleDone(). This in turn calls the animation setter, which tries to run change detection (https://github.com/primefaces/primeng/blame/master/src/app/components/accordion/accordion.ts#L77).
  3. If the component has already been destroyed, the ViewDestroyedError is thrown.

It doesn't cause the spec to fail, but it does create a ton of these errors in the log. Perhaps just add an internal property for isDestroyed that is set to true in onDestroy(), and then check to make sure it is still false before calling detectChanges()?

@sticl
Copy link

sticl commented Aug 12, 2019

Same problem here (same error coming from onToggleDone()), this only shows up when in debug mode.

@cicciogeppo88
Copy link

cicciogeppo88 commented Aug 16, 2019

Hello!
I am having the same troubles here, tests are passing but errors are thrown.
Is there any fix available to this bug? all help will be appreciated,

Details:
Angular cli v 8.1.2
Angular core 8.1.3
Karma 4.2.0
Jasmine core 3.4.0
Prime NG v 8.0.2

Thanks

@yigitfindikli
Copy link
Contributor

Hi,
Can you provide stackblitz sample using with https://stackblitz.com/github/primefaces/primeng-issue-template .

@brian428
Copy link
Contributor Author

Like I said in the initial report, I'm not sure how to provide an example because I only see this during unit testing, where a test completes and the component is destroyed before the Accordion finishes animating.

I think my initial description tells the whole story though. If you just look at the code I linked to above you can clearly see the problem. There's no check in place to make sure the component hasn't been destroyed before it runs detectChanges().

I think onDestroy() just needs to set a flag like this.isDestroyed = true;, and then the animating setter would just become:

set animating(val: boolean) {
    this._animating = val;
    if(!this.isDestroyed) this.changeDetector.detectChanges();
}

@cicciogeppo88
Copy link

@yigitfindikli same comment as @brian428 can't provide an example as well; what I could understand is that a singular test ran with Fit (even if is obsolete) is not throwing errors, but if I run more tests together, some of these are throwing errors.

@gferreira-keeps
Copy link

I've done a pull request using a solition also proposed by @brian428 (#8083).

@cicciogeppo88
Copy link

Hello there,
Thank you @gferreira-keeps , do you know when this will be approved/released?
I would like to try it to see if is working and fixing this topic's issue,

Thanks

@cagataycivici cagataycivici added the Type: Bug Issue contains a bug related to a specific component. Something about the component is not working label Sep 5, 2019
@cagataycivici cagataycivici added this to the 8.1.0 milestone Sep 5, 2019
cagataycivici added a commit that referenced this issue Oct 7, 2019
fixed #8044 AccordionTab throwing ViewDestroyedError during unit testing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants