Reputation: 1259
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!
Upvotes: 4
Views: 2614
Reputation: 10647
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".
Upvotes: 3