Can't get $.ajax.mostRecentCall to work with jasmine 2.0.2

点点圈 提交于 2019-12-10 12:34:23

问题


Having real trouble getting a simple example to work. I am using this example taken from https://gist.github.com/Madhuka/7854709

describe("Test for spies", function() {
 function sendRequest(callbacks, configuration) {
        $.ajax({
            url: configuration.url,
            dataType: "json",
            success: function(data) {
                callbacks.checkForInformation(data);
            },
            error: function(data) {
                callbacks.displayErrorMessage();
            },
            timeout: configuration.remainingCallTime
        });
    }

    it("should make an Ajax request to the correct URL", function() {

    var configuration = {
        url : "http://www.google.com",
        remainingCallTime : 30000
    };

        spyOn($, "ajax");

        sendRequest(undefined, configuration);
        expect($.ajax.mostRecentCall.args[0]["url"]).toEqual(configuration.url);
    });
});

For whatever reason, $.ajax.mostRecentCall is undefined.

Using jasmine 2.0.2 and jasmine jquery 2.0.5.

Fiddle here: http://jsfiddle.net/sidouglas/85b35993/


回答1:


This the old 1.x Jasmine syntax:

$.ajax.mostRecentCall.args

The syntax for Jasmine 2 is:

$.ajax.calls.mostRecent().args

So your assertion should be:

expect($.ajax.calls.mostRecent().args[0]["url"]).toEqual(configuration.url);


来源:https://stackoverflow.com/questions/27239824/cant-get-ajax-mostrecentcall-to-work-with-jasmine-2-0-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!