isaacplmann / ngx-contextmenu

An Angular component to show a context menu on an arbitrary component
MIT License
248 stars 91 forks source link

Jasmine Testing Components w/ context-menu #167

Open dalexander-trc opened 5 years ago

dalexander-trc commented 5 years ago

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:

  1. Create a component and include a context-menu, any of the samples provided on the GitHub page will do.
  2. Attempt to run a jasmine test. You must include the ContextMenuService and ContextMenuModule to get past injection and binding errors, respectively.
  3. 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

jarodsmk commented 5 years ago

In your stackblitz, I changed:

providers: [ {provide: ContextMenuService }]

to:

providers: [ ContextMenuService ]

and seems to work fine