【发布时间】:2019-05-08 00:10:11
【问题描述】:
我正在尝试监视 window.alert。我已经监视了窗口的警报功能,但它仍然说它必须被监视。 我的组件有
method1(){
method2();
}
method2{
if(some condition){
alert('hello');
}
}
我的单元测试:
it('it should say hello', () => {
spyOn(component, 'method1').and.callThrough();
spyOn(window, 'alert');
component.method1();
expect(window.alert).toHaveBeenCalledWith('hello');
}
错误是 预期的间谍警报已使用 ['hello'] 调用,但从未调用过
【问题讨论】:
-
你能给出描述的错误的有效复制吗?因为你的代码应该可以工作。
标签: javascript angular unit-testing jasmine angular6