I'm using PrimeNG Tree component inside my component. The relevant part of HTML looks like this:
<p-tree
[value]="allTreeNodes"
selectionMode="checkbox"
[filter]="true"
(onNodeSelect)="nodeSelect($event)"
data-testid="analysis-tree"
></p-tree>
As you can see, I handle onNodeSelect
in my .component.ts
file, but I don't handle onNodeExpand
. My question is what happens when node is expanded? Does PrimeNG somehow handles it automatically? Can I somehow prove that the default event handler is run? Additionally, is there anything else I need to do from unit test for that event to reach Tree component? I tried this and the test fails at last line:
const element: DebugElement = TestUtils.findEl(fixture, 'analysis-tree');
element.triggerEventHandler('onNodeExpand', {
node: typeNode1
});
fixture.detectChanges();
expect(typeNode1?.expanded).toBeTruthy();
I would've expected that default event handler sets expanded
to true on TreeNode, but it seems I was wrong.