vendredi 21 août 2015

$httpBackend jsonp: No pending requests to flush

On a button click, I make a jsonp call.

    function clickHandler(e) {
            e.preventDefault();
            var url = "some.url.with?params";
            $http.jsonp(url).success(function () {$scope.success();})
                            .error(function () {$scope.failure();});
        }

Test:

$httpBackend.expectJSONP(this.url + '&' + $.param(this.params)).respond({status: 200});

$('button').click();

$rootScope.$digest(); // this was suggested in few answers, doesn't work for me though

$httpBackend.flush();

But I keep getting the No pending requests to flush failure.

Is there something different we need to do incase of JSONP calls. Everywhere else, this format works.

PS: yes I make the call(many questions, people actually din make the call or trigger the action that triggered the event). Atleast, I see the code hitting the line where I made the request in the code.

Aucun commentaire:

Enregistrer un commentaire