【问题标题】:How to write the test case in Jasmine in Angular2 for redirect URL?如何在 Angular2 的 Jasmine 中为重定向 URL 编写测试用例?
【发布时间】:2016-12-19 09:16:31
【问题描述】:
SecurityService.prototype.Feedback = function () {
    window.open('https://www.google.com/', '_blank');

我需要在 Angular 2 中用 Jasmine 编写上述代码的测试用例。

【问题讨论】:

    标签: javascript angular jasmine testcase


    【解决方案1】:

    我建议你使用 $window 而不是 window。

    如果你这样做,你可以像这样轻松地测试它:

    spyOn($window, 'open');
    
    //call your function here
    
    expect($window.open).toHaveBeenCalledWith('https://www.google.com/', '_blank');
    

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-11
      • 1970-01-01
      • 1970-01-01
      • 2021-10-15
      • 1970-01-01
      • 1970-01-01
      • 2019-05-01
      • 1970-01-01
      相关资源
      最近更新 更多