[英]How to unit test alert in angular 2 by using Jasmine?
我試圖通過在角度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'); });
您可以嘗試在窗口上進行監視,然后檢查是否已使用例外值調用警報,例如:
it("should call alert", () => {
spyOn(window, "alert");
//your code
expect(window.alert).toHaveBeenCalledWith("expected message");
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.