我在组件模板中有这段代码,它打开了一个 ngx-bootstrap 模式:
<button type="button"
class="btn btn-primary"
(click)="onOpenSharesModal(modal)">Click me!</button>
<ng-template #modal>
<app-modal (closed)="onCloseSharesModal()"></app-modal>
</ng-template>
零件:
onOpenSharesModal(template: TemplateRef<any>) {
this.modalRef = this.modalService.show(template, { class: 'modal-lg' });
}
测试:
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();
});
我正在尝试测试组件:我已经能够测试onOpenSharesModal()
正在调用的组件,但我想测试它是否以modal
模板变量作为参数调用。我怎样才能做到这一点?