Sp *_*aju 3 unit-testing karma-jasmine angular
我试图通过在 angular 2 中使用 Jasmine 来编写一个警报测试用例。但是我的测试用例是如何给出错误的,即使我不确定我是否编写了正确的方法。如果有任何想法,请帮助我。
这是我的测试用例:
it('checking showscheduledrequest flow an alert is called',() =>{
let component = fixture.componentInstance;
component['ou'] = 'd';
component['sen'] = 'ddsd';
var oldalert = alert;
oldalert = jasmine.createSpy();
component.handleActionChane('showscheduledrequest');
fixture.autoDetectChanges();
expect(alert).toHaveBeenCalledWith('This is not a valid request');
});Run Code Online (Sandbox Code Playgroud)
小智 7
您可以尝试监视窗口,然后检查是否已使用异常值调用警报,例如:
it("should call alert", () => {
spyOn(window, "alert");
//your code
expect(window.alert).toHaveBeenCalledWith("expected message");
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2425 次 |
| 最近记录: |