测试茉莉花角@ViewChild

时间:2021-06-01 12:52:01

标签: angular unit-testing karma-jasmine angular-unit-test

我有以下组件

<app-modal-default #confirmDelete>
<span class="title">Delete Confirmation</span>
<span class="modal-body-content">Do you want to delete all the data related to shipping, distribution and storage?
</span>
<div class="modal-actions">
    <button class="btn btn-danger" (click)="confirmDeleteOk()">Delete</button>&nbsp;
    <button class="btn-default btn" (click)="close(confirmDelete)">
        Cancel
    </button>
</div>

我在 .ts 文件中声明了一个视图子

@ViewChild('confirmDelete') confirmDelete: ModalDefaultComponent;

这个视图子我正在这个函数中关闭

confirmDeleteOk(): void {
 this.hTstore$.dispatch(new fromHTAction.DeleteWMS());
 this.close(this.confirmDelete);
}

这是我的测试文件

it('Calling WMS delete through dispatch Action Should work as expected', fakeAsync((done) => {
 component.confirmDeleteOk();
 storeSpy.dispatch(new DeleteWMS());
 expect(storeSpy.dispatch).toHaveBeenCalledWith(new DeleteWMS()); }));

iam getting an test error

TypeError: element.close 不是函数

如何为我的 element.close 编写视图子项的测试,我如何定义元素?

0 个答案:

没有答案