weixin_33709364 2015-02-10 09:58 采纳率: 0%
浏览 34

带有茉莉花的茉莉花模拟ajax

I have tried to mock/stub my ajax call, but it looks like it only works with text. When I tried to set response with object then my done callback is not called:

jasmine.Ajax.stubRequest('/some_url/1').andReturn({
  //"responseText": response ,
 "response": response,
  "status": 200
});

, but when I set responseText with object then it is called, but the responseJSON is not set, when debug response in FF

responseJSON undefined
status 200
statusText "success"

Am I doing something wrong or it is an issue?

I am using Jasmine 2.1.3 and latest version of jasmine-ajax (honestly I cannot figure it out where I can find version I am using...;-), I've just downloaded mock-ajax.js from link in documentation in github)

UPDATE: It was my bad. I have tried to push plain Object, when used JSON.stringify and pass the result to "responseText" it works!

  • 写回答

1条回答 默认 最新

  • 三生石@ 2015-02-11 18:44
    关注

    Instead of using the "response" attribute, you need to use either "responseText" or "responseJSON", depending upon your stubbed data's type.

    If your response is already parsed JSON (i.e., an actual JSON object and not a string), then use "responseJSON".

    评论

报告相同问题?