Test a function passed as argument to another func

2019-09-15 01:02发布

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?

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');

            }
        }

标签: jasmine
1条回答
放荡不羁爱自由
2楼-- · 2019-09-15 01:23

Yes. You can do that using jasmine.any

Quoting the documentation example:

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

Hope that helps!

查看更多
登录 后发表回答