3

I have the following jasmine spec:

describe "plugins", ->
    beforeEach ->
    @server = sinon.fakeServer.create()

    afterEach ->
    @server.restore()

    describe "reviewStatus", ->
    it "should attach dates to content", ->
      @server.respondWith("GET", "/GeneralDocument.mvc.aspx/GetDocumentParent?typeName=ncontinuity2.core.domain.Plan&documentParentUid=45f0bccb-27c9-410a-bca8-9ff900ab4c28d",
        [200, {"Content-Type": "application/json"},
        '{"ReviewDate":"22/09/2012","AcknowledgedDate":"05/07/2012"}'])   

      $('#jasmine_content').addReviewStatus('ncontinuity2.domain.Plan', "45f0bccb-27c9-410a-bca8-9ff900ab4c28")     

      @server.respond()

      expect($('#reviewDateTab').find("strong").eq(0).length).toEqual(1)

The addReviewStatus is a jQuery plugin I have written:

do($ = jQuery) ->
    $.fn.extend
        addReviewStatus: (type, uid) ->
            ele = @

            reviewData = null           

            getJSON '/GeneralDocument.mvc.aspx/GetDocumentParent', {typeName: type, documentParentUid: uid}, 
                                (document) ->
                                    console.log('document = ' + document)
                                    compileTemplate(ele, document)
                                (response) ->
                                    showErrorMessage resonse.responseText
#etc., etc.

The getJSON method above calls $.ajax like this:

function getJSON(url, params, ajaxCallBack, ajaxErrorHandler, excludeProgress){
    var e = (ajaxErrorHandler) ? ajaxErrorHandler : validationErrorCallBack;
    var s = (ajaxCallBack) ? ajaxCallBack : jsonCallBack;
    $.ajax({
        type: "GET",
        url: url,
        cache: false, 
        data: params,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("Ajax", "true");
            xhr.setRequestHeader("UseAjaxError", "true");
        },
        complete: function() {
        },
        success: s,
        timeout: _ajaxTimeOut,
        dataType: "json",
        error: e
    });
}

The anonymous function callback of the getJSON method is not being fired. Also the call to $.ajax is returning a 404 not found. Can anyone see what I am doing wrong?

4

2 に答える 2

2

私も同様の問題を抱えています。これは、AJAX呼び出しでキャッシュをオフにすることに関連しているようです。回避できたらもっと投稿します。テスト用にキャッシュをオフにして、合格するかどうかを確認してみてください。しかし、なぜそれが必要なのかわかりません。

ロナン

于 2012-03-22T14:19:25.317 に答える
2

Sinon fakeserverは、呼び出したURLに応答が割り当てられていない場合、404を返します。

問題は、呼び出しているURLがrespondWith()パラメーターのURLと正確に一致していないことです。また、SinonではURLの長さに制限があるかもしれませんが、確かではありません。

于 2014-03-07T01:26:24.940 に答える