本文介绍了测试作为参数传递给Jasmine中另一个函数的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在调用 tohaveBeenCalledWith
时收到以下错误(这是正常的!):
I am getting below error(which is OK!) when called tohaveBeenCalledWith
:
spy showError to have been called with [ '33' ] but actual calls were [ Function, 403 ]
我有没有办法测试函数调用的函数?
Is there any way I can test Function that the function called with?
假设参数函数是testFun ,如何测试$ window.location.href是否已应用正确的值
Assuming that the argument Function is testFun, How can I test if $window.location.href hascorrect value applied
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');
}
}
推荐答案
是。你可以使用
Yes. You can do that using jasmine.any
引用文档示例:
expect(foo).toHaveBeenCalledWith(jasmine.any(Number), jasmine.any(Function));
希望有所帮助!
这篇关于测试作为参数传递给Jasmine中另一个函数的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!