测试作为参数传递给Jasmine中另一个函数的函数

时间:2016-12-29 08:59:42

标签: jasmine

我在调用tohaveBeenCalledWith时遇到错误(这是正常的!):

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

我有没有办法测试功能函数调用?

假设参数函数是testFun ,如何测试$ window.location.href是否已应用正确的值

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 个答案:

答案 0 :(得分:1)

是。您可以使用jasmine.any

执行此操作

引用文档示例:

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

希望有所帮助!