mardi 24 juillet 2018

Access instance of MatMenuTrigger component in Angular test

I'm trying to create a test for Angular component that contains MatMenu from Angular Material in its template. I want to test items inside that menu. It turns out that HTML inside MatMenu is compiled only after opening the menu so I need to invoke an openMenu method on menu trigger somehow. The problem is I cannot find a way to get a reference to MatMenuTrigger component in Angular test. For most of the components when I query them using for e.g. debugElement.queryAllNodes(By.directive(MatIcon)) I get a DebugElement with a componentInstance property which is exactly what I need, but unfortunately for MatMenuTrigger it doesn't work that way. I don't know why but this code debugElement.queryAllNodes(By.directive(MatMenuTrigger))[0].componentInstance is returning parent component instance (same as debugElement.componentInstance), not the MatMenuTrigger that I can use to open menu.

Is this a bug in Angular testing framework or am I doing something wrong?

Aucun commentaire:

Enregistrer un commentaire