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".

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘