Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

>> How to spyon a an Ajax call and load response text by own yourself instead of server.
>     here's the code with explanation.... (smile)

spyOn(Ext.Ajax, 'request').andCallFake(function (request) {
var response = {
responseText: " response that you want to load (may be a valid json file ) here is you can hardcode in the server response text",
status: 200 // here define the status code which you want 200,501,..
};

request.success = 'true'; // as when server loads response its success is true but here we have to make success true by ourself only...

// this callback is loading response(defined above) in into the store instead of loading a an actual reponse from server
// callback(options,success,reponse){ }
// options are null (currently no clue about it but it works )

request.callback(null, true, response);

});

mainList = Ext.create('Screener.store.Patients'); // creation of store will call Ajax request and from here spyon works.

// you may have created mainList above in describe, but here also its needed for Ajax call

 

...

now you can check if the data in mainList is the same as what you have hardcoded in responseText