如何为$ .Post()编写业力测试。失败() [英] How Do I Write Karma Test For $.Post().Fail()

查看:88
本文介绍了如何为$ .Post()编写业力测试。失败()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$ .post()。fail()的情况是在karma测试运行器中给出错误。 TypeError:无法读取未定义的属性'fail'。



如何为$ .post()。fail()和done()编写测试。



我的角度代码在这里:

The case for $.post().fail() is giving error in karma test runner. "TypeError: Cannot read property 'fail' of undefined".

How do i write test for $.post().fail()and done().

My angular code is here :

$scope.fetch_data = function (urlbase) {
        $.post(urlbase + "/GetBranchMapping", null, function (data) {
            $scope.branchInstanceList = data;
            $scope.$apply();
            $("#divLoading").hide();
        }, "json").fail(function (xhr, status, error) {
            if (xhr.status == 500) {
                $("#divLoading").hide();
                alert(error);
            }
            else if (xhr.status == "403") {
                alert("You are not authorized to view this page.");
                xhr.status = "0";
            }
        });
    };





我的测试用例在这里:



And my test case is here :

it("should be able to hide div", function () {
        var fakeData = "This will be the new html";
        var fakeError="Error";
        spyOn($, "ajax").andCallFake(function(params) {
            params.success(fakeData);
        });

        //var elm = compiled('<div id="divLoading">loading...</div>')(scope);

        scope.fetch_data('https://localhost/reportingblotter');


        //elm.hide();
        expect($('#divLoading').css('display')).toBe('none');


    })





paramas.success()的间谍正在工作,而如果我使用params.fail()不是。



如果有人有解决方案,请帮助我。



Spy for paramas.success() is working, whereas if i used params.fail() its not.

Please help me if anyone has solution.

推荐答案

.post()。fail()在karma测试运行器中给出错误。 TypeError:无法读取未定义的属性'fail'。



如何为
.post().fail() is giving error in karma test runner. "TypeError: Cannot read property 'fail' of undefined".

How do i write test for

.post()编写测试.fail()和done()。



我的角度代码在这里:

.post().fail()and done().

My angular code is here :


范围.fetch_data = function (urlbase){
scope.fetch_data = function (urlbase) {


这篇关于如何为$ .Post()编写业力测试。失败()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆