无法获得$ .ajax.mostRecentCall茉莉花2.0.2工作茉莉花、工作、ajax、mostRecentCall

2023-09-10 19:09:23 作者:我不太會說話

有真正的麻烦一个简单的例子来工作。我用这个例子从 https://gist.github.com/Madhuka/7854709

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

无论出于何种原因, $。ajax.mostRecentCall 是不确定的。

使用2.0.2茉莉花和茉莉花的jQuery 2.0.5。

Using jasmine 2.0.2 and jasmine jquery 2.0.5.

小提琴在这里: http://jsfiddle.net/sidouglas/85b35993/

推荐答案

这老1.x的茉莉花语法:

This the old 1.x Jasmine syntax:

$.ajax.mostRecentCall.args

的语法茉莉花2:

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