ngx-contextmenu
ngx-contextmenu copied to clipboard
Jasmine Testing Components w/ context-menu
Describe the bug Jasmine tests fail for components that include context-menu tags in their HTML. I didn't see anything in the documentation describing how to handle this.
To Reproduce Steps to reproduce the behavior:
- Create a component and include a context-menu, any of the samples provided on the GitHub page will do.
- Attempt to run a jasmine test. You must include the ContextMenuService and ContextMenuModule to get past injection and binding errors, respectively.
- See error (simplified below, full stack is available at StackBlitz)
TypeError: Cannot read property 'show' of undefined ... at Jasmine at new ContextMenuComponent at createClass at createDirectiveInstance at createViewNodes at callViewAction . . .
Expected behavior Ideally if I wanted to test a context menu implementation I would put it in its own component and test it there. In this situation, I would prefer if the menu was ignored entirely as I intend to test only the functionality native to the component itself.
Stackblitz Example https://stackblitz.com/edit/ngx-contextmenu-example-b9cxub https://ngx-contextmenu-example-b9cxub.stackblitz.io
In your stackblitz, I changed:
providers: [ {provide: ContextMenuService }]
to:
providers: [ ContextMenuService ]
and seems to work fine