角茉莉 - 期望()。tohavebeencalled()不起作用
如果有人可以帮助我调试我的单位测试代码,我将不胜感激。基本上,我正在尝试测试在按钮的单击()事件时是否调用了几种方法。它们在实际应用程序上运行良好,但显然不是在测试时:
fit('Cancel button should trigger dialog modal', () => {
spyOn(_myService, 'showDialogModal');
spyOn(component, 'confirmCancel');
const cancelButton = fixture.debugElement.nativeElement.querySelector('.cancelButton');
cancelButton.click();
fixture.detectChanges();
expect(component.confirmCancel).toHaveBeenCalled();
expect(_myService.showDialogModal).toHaveBeenCalledWith(
header, message
);
});
执行时,我得到了:
expect(spy).toHaveBeenCalled()
Expected number of calls: >= 1
Received number of calls: 0
这是用于方法component.confirmcancel()
,而第二个是从该函数中调用的。 。
if anyone can help me debug my unit test code I would appreciate it. Basically I'm attempting to test whether a couple of methods are invoked upon a button's click() event. They run fine on the actual app, but apparently not while testing:
fit('Cancel button should trigger dialog modal', () => {
spyOn(_myService, 'showDialogModal');
spyOn(component, 'confirmCancel');
const cancelButton = fixture.debugElement.nativeElement.querySelector('.cancelButton');
cancelButton.click();
fixture.detectChanges();
expect(component.confirmCancel).toHaveBeenCalled();
expect(_myService.showDialogModal).toHaveBeenCalledWith(
header, message
);
});
Upon execution, I'm getting:
expect(spy).toHaveBeenCalled()
Expected number of calls: >= 1
Received number of calls: 0
This is for the method component.confirmCancel()
, whereas the second one is called from within that function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调试的两个想法:
如果您还发布了组件的相关HTML和TS代码,则可能会有所帮助。
Two ideas for debugging:
It could be helpful if you also post the relevant html and ts code of the component.