I have this code in a component template, which opens a ngx-bootstrap modal:
<button type="button"
class="btn btn-primary"
(click)="onOpenSharesModal(modal)">Click me!</button>
<ng-template #modal>
<app-modal (closed)="onCloseSharesModal()"></app-modal>
</ng-template>
Component:
onOpenSharesModal(template: TemplateRef<any>) {
this.modalRef = this.modalService.show(template, { class: 'modal-lg' });
}
Test:
it('should call onOpenSharesModal() when button clicked', () => {
const button = fixture.debugElement.query(By.css('button'));
const spy = spyOn(component, 'onOpenSharesModal');
button.triggerEventHandler('click', null);
fixture.detectChanges();
expect(spy).toHaveBeenCalled();
});
I'm trying to test the component: I've been able to test that onOpenSharesModal()
is being called, but I'd like to test if it was called with the modal
template variable as argument. How can I do that?