我有以下茉莉花规格:
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)
addReviewStatus 是我编写的一个 jQuery 插件:
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.
上面的 getJSON 方法像这样调用 $.ajax:
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
});
}
未触发 getJSON 方法的匿名函数回调。对 $.ajax 的调用也返回 404 not found。谁能看到我做错了什么?