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

Component: Block UI - JEST error when destroy component if 'mask' is undefined #12254

Closed
maximegris opened this issue Nov 18, 2022 · 0 comments · Fixed by #12255
Closed

Component: Block UI - JEST error when destroy component if 'mask' is undefined #12254

maximegris opened this issue Nov 18, 2022 · 0 comments · Fixed by #12255
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@maximegris
Copy link
Contributor

maximegris commented Nov 18, 2022

Describe the bug

After running a JEST test on a component depending on BlockUI, the test failed during the clean up phase (when ngOnDestroy functions are called)

console.error
    Error during cleanup of component {
      component: AppComponent {
        [...],
stacktrace: TypeError: Cannot read properties of undefined (reading 'nativeElement')
          at BlockUI.unblock ([PROJECT_PATH]\node_modules\primeng\fesm2015\primeng-blockui.mjs:64:19)
          at BlockUI.ngOnDestroy ([PROJECT_PATH]\node_modules\primeng\fesm2015\primeng-blockui.mjs:82:14)
          at executeOnDestroys ([PROJECT_PATH]\node_modules\@angular\core\fesm2015\core.mjs:8809:32)
          at cleanUpView ([PROJECT_PATH]\node_modules\@angular\core\fesm2015\core.mjs:8710:9)

This appears because this.mask can be undefined when blockUi componant is destroyed.

   unblock() {
        this.animationEndListener = this.destroyModal.bind(this);
        this.mask.nativeElement.addEventListener('animationend', this.animationEndListener); //***mask can be undefined here***
        DomHandler.addClass(this.mask.nativeElement, 'p-component-overlay-leave'); //***mask can be undefined here***
    }

    destroyModal() {
        this._blocked = false;
        DomHandler.removeClass(this.mask.nativeElement, 'p-component-overlay-leave'); //***mask can be undefined here***
        ZIndexUtils.clear(this.mask.nativeElement); //***mask can be undefined here***
        this.el.nativeElement.appendChild(this.mask.nativeElement); //***mask can be undefined here***
        this.unbindAnimationEndListener();
        this.cd.markForCheck();
    }

    unbindAnimationEndListener() {
        if (this.animationEndListener && this.mask) { // this.mask check is already made here but not in the above functions
            this.mask.nativeElement.removeEventListener('animationend', this.animationEndListener);
            this.animationEndListener = null;
        }
    }

    ngOnDestroy() {
        this.unblock();
        this.destroyModal();
    }

Environment

Windows 10
NodeJS 18.12.0
Angular 14.2.0
Jest 28.1.1

Reproducer

No response

Angular version

14.2.0

PrimeNG version

14.2.2

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

18.12.0

Browser(s)

No response

Steps to reproduce the behavior

No response

Expected behavior

No response

@maximegris maximegris added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Nov 18, 2022
@cetincakiroglu cetincakiroglu removed the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Nov 28, 2022
@cetincakiroglu cetincakiroglu added this to the 15.0.0 milestone Nov 28, 2022
@cetincakiroglu cetincakiroglu added the Type: Bug Issue contains a bug related to a specific component. Something about the component is not working label Dec 12, 2022
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
2 participants