2016-12-29 115 views
0

我收到以下錯誤(這是OK!)呼籲tohaveBeenCalledWith時傳遞給另一個函數的函數:測試作爲參數在茉莉花

spy showError to have been called with [ '33' ] but actual calls were [ Function, 403 ] 

有沒有什麼辦法可以測試功能調用函數用?

假設參數功能是testFun,如何測試如果應用

function testFun(errorStatus) { 
      switch (errorStatus) { 
       case 401: 
        $window.location.href = url1; 
        break; 
       case 403: 
        $window.location.href = url2; 
        break;    
       default: 
        console.log('Something went wrong'); 

      } 
     } 

回答

1

是$ window.location.href hascorrect值。你可以做,使用jasmine.any

引用文檔例如:

expect(foo).toHaveBeenCalledWith(jasmine.any(Number), jasmine.any(Function)); 

希望幫助!

+0

感謝您的回覆。 假設參數函數是testFun,如何測試如果$ window.location.href hascorrect值施加 'code' 功能testFun(ErrorStatus中){ 開關(ErrorStatus中){ 箱401: $ window.location的。 href = url1; 休息; case 403: $ window.location.href = url2; 休息; 默認值: console.log('出錯了'); } } –

+0

@PravinVarma這裏不可讀。請更新問題本身 – tanmay

+0

@PravinVarma只是把'jasmine.any(函數)'放在你得到那個錯誤的參數中。這應該工作 – tanmay