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: Menu logs error in jest when using [popup]=true and the toggle($event) method #16812

Open
rg1220 opened this issue Nov 21, 2024 · 1 comment
Labels
Resolution: Help Wanted Issue or pull request requires extra help and feedback
Milestone

Comments

@rg1220
Copy link

rg1220 commented Nov 21, 2024

Describe the bug

I'm still trying to come up with the most simple reproducible case. However, it appears that menu.toggle($event) now requires an event object that includes the currentTarget property (only when using [popup]="true"). This change appears to have been made between [email protected] (no error) and [email protected] (started getting an error). It also seems to not be happening in Chrome but it is happening in Jest; which I'm not sure why but still looking at the source as to why.

The toggle method requires an event as it is documented here https://primeng.org/menu#api.menu.methods.toggle. However, as a developer, it doesn't feel like it should be required or if it really needs something the toggle method should be more specific than a generic "Event".

<p-menu #menu [popup]="true" .... ></p-menu>
@ViewChild(Menu) menu: Menu;

myMethod() {
  this.menu.toggle({});
}

Doing this in Jest, we are getting this error:

console.error
ERROR TypeError: Cannot read properties of undefined (reading 'offsetHeight')
    at Function.absolutePosition (/Users/me/WebstormProjects/ourapp/node_modules/primeng/fesm2022/primeng-dom.mjs:163:42)
    at _Menu.alignOverlay (/Users/me/WebstormProjects/ourapp/node_modules/primeng/fesm2022/primeng-menu.mjs:407:24)
    at _Menu.onOverlayAnimationStart (/Users/me/WebstormProjects/ourapp/node_modules/primeng/fesm2022/primeng-menu.mjs:380:26)
    at _Menu_div_0_Template_div_animation_overlayAnimation_start_0_listener (ng:///_Menu/ɵcmp.js:262:40)
    at executeListenerWithErrorHandling (/Users/me/WebstormProjects/ourapp/node_modules/@angular/core/fesm2022/core.mjs:25629:16)
    at fn (/Users/me/WebstormProjects/ourapp/node_modules/@angular/core/fesm2022/core.mjs:25663:22)
    at /Users/me/WebstormProjects/ourapp/node_modules/@angular/animations/fesm2022/browser.mjs:4780:25
    at Array.forEach (<anonymous>)
    at /Users/me/WebstormProjects/ourapp/node_modules/@angular/animations/fesm2022/browser.mjs:4778:46
    at _ZoneDelegate.Object.<anonymous>._ZoneDelegate.invoke (/Users/me/WebstormProjects/ourapp/node_modules/zone.js/bundles/zone.umd.js:416:30)
    at Object.onInvoke (/Users/me/WebstormProjects/ourapp/node_modules/@angular/core/fesm2022/core.mjs:18555:33)
    at _ZoneDelegate.Object.<anonymous>._ZoneDelegate.invoke (/Users/me/WebstormProjects/ourapp/node_modules/zone.js/bundles/zone.umd.js:415:56)
    at Zone.Object.<anonymous>.Zone.run (/Users/me/WebstormProjects/ourapp/node_modules/zone.js/bundles/zone.umd.js:173:47)
    at NgZone.run (/Users/me/WebstormProjects/ourapp/node_modules/@angular/core/fesm2022/core.mjs:18406:28)
    at /Users/me/WebstormProjects/ourapp/node_modules/@angular/animations/fesm2022/browser.mjs:4777:28
    at _ZoneDelegate.Object.<anonymous>._ZoneDelegate.invokeTask (/Users/me/WebstormProjects/ourapp/node_modules/zone.js/bundles/zone.umd.js:450:35)
    at Zone.Object.<anonymous>.Zone.runTask (/Users/me/WebstormProjects/ourapp/node_modules/zone.js/bundles/zone.umd.js:218:51)
    at drainMicroTaskQueue (/Users/me/WebstormProjects/ourapp/node_modules/zone.js/bundles/zone.umd.js:639:39)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

  14 | jest.spyOn(console, 'error').mockImplementation((...args) => {
  15 |   if (args[1] !== FAKE_ERROR) {
> 16 |     consoleerror.call(console, ...args);
     |                  ^
  17 |   }
  18 | });
  19 |

  at console.<anonymous> (src/test-setup.ts:16:18)
  at ErrorHandler.handleError (../../../node_modules/@angular/core/fesm2022/core.mjs:6531:23)
  at handleError (../../../node_modules/@angular/core/fesm2022/core.mjs:12372:34)
  at executeListenerWithErrorHandling (../../../node_modules/@angular/core/fesm2022/core.mjs:25632:9)
  at fn (../../../node_modules/@angular/core/fesm2022/core.mjs:25663:22)
  at ../../../node_modules/@angular/animations/fesm2022/browser.mjs:4780:25
      at Array.forEach (<anonymous>)
  at ../../../node_modules/@angular/animations/fesm2022/browser.mjs:4778:46
  at _ZoneDelegate.Object.<anonymous>._ZoneDelegate.invoke (../../../node_modules/zone.js/bundles/zone.umd.js:416:30)
  at Object.onInvoke (../../../node_modules/@angular/core/fesm2022/core.mjs:18555:33)
  at _ZoneDelegate.Object.<anonymous>._ZoneDelegate.invoke (../../../node_modules/zone.js/bundles/zone.umd.js:415:56)
  at Zone.Object.<anonymous>.Zone.run (../../../node_modules/zone.js/bundles/zone.umd.js:173:47)
  at NgZone.run (../../../node_modules/@angular/core/fesm2022/core.mjs:18406:28)
  at ../../../node_modules/@angular/animations/fesm2022/browser.mjs:4777:28
  at _ZoneDelegate.Object.<anonymous>._ZoneDelegate.invokeTask (../../../node_modules/zone.js/bundles/zone.umd.js:450:35)
  at Zone.Object.<anonymous>.Zone.runTask (../../../node_modules/zone.js/bundles/zone.umd.js:218:51)
  at drainMicroTaskQueue (../../../node_modules/zone.js/bundles/zone.umd.js:639:39)

Environment

[email protected]

Reproducer

No response

Angular version

17.3.7

PrimeNG version

18.17.12

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

20.17.0

Browser(s)

No response

Steps to reproduce the behavior

No response

Expected behavior

No response

@rg1220 rg1220 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 21, 2024
@mertsincan mertsincan added Resolution: Help Wanted Issue or pull request requires extra help and feedback and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Nov 22, 2024
@mertsincan mertsincan added this to the Future milestone Nov 22, 2024
Copy link

Due to PrimeNG team's busy roadmap, this issue is available for anyone to work on. Make sure to reference this issue in your pull request. ✨ Thank you for your contribution! ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Help Wanted Issue or pull request requires extra help and feedback
Projects
None yet
Development

No branches or pull requests

2 participants