【发布时间】:2021-11-15 09:08:03
【问题描述】:
我运行了这个测试,但我得到了这个错误:
Unhandled Promise rejection: <toHaveBeenCalledWith> : Expected a spy, but got Function.
it('should change myComponent value', () => {
spyOn(component.mychange, 'emit');
const input = fixture.debugElement.query(By.css('#mychange')).nativeElement;
input.value = "2";
fixture.whenStable().then(() => {
expect(component.mychange.emit).toHaveBeenCalledWith(2);
});
});
有类似的问题,但是在发出事件时发生在我身上,我尝试了这些问题的解决方案,但它们不起作用。
【问题讨论】:
-
如果你将 spyOn 分配给一个变量并在稳定时使用它会发生什么?
-
错误:预期的间谍发射已被调用:[ 2 ],但从未调用过。
标签: angular unit-testing testing karma-jasmine