您好我正在为Jasmine中的角度代码编写单元测试用例。我的弹出窗口中有模态。点击按钮,我打开模态。
以下是我的组件代码。
//declaration
@ViewChild('editorModal')
editorModal: ModalDirective;
//button click
addScope() {
this.formResetToggle = false;
setTimeout(() => {
this.formResetToggle = true;
this.scopeEdit = new Scope();
this.scopeEdit.scopevalue = '';
this.editorModal.show();
});
}
以下是我的HTML代码。
<div class="modal fade" bsModal #editorModal="bs-modal" tabindex="-1" id="myModal" role="dialog" aria-labelledby="myModalLabel">
</div>
以下是我的单元测试。
it('open popup to add scope', () => {
component.addScope();
expect(component.editorModal.show).toHaveBeenCalled(); //error
});
我正在尝试编写断言语句以确保我的模态已被打开。有人可以帮助我使上面的代码工作?任何帮助,将不胜感激。谢谢